soegaard2
2020-10-16 08:46:38

Macro of the day: ; SYNTAX (store id ...) ; Make hashtable storing the values to which the ids are bound. ; The key is the symbol corresponding to the identifier. (define-syntax (store stx) (syntax-parse stx [(_store id ...) (syntax/loc stx (make-hasheq (list (cons 'id id) ...)))])) ; SYNTAX (load ht (id ...)) ; Define the ids use initial values stored in the hash table. (define-syntax (load stx) (syntax-parse stx [(_store the-ht (id ...)) (syntax/loc stx (begin (define ht the-ht) (define id (hash-ref ht 'id)) ...))])) ;; Example (define x 42) (define y 'a) (define info (store x y)) info ; => '#hasheq((x . 42) (y . a)) (let () (load info (x y)) (list x y)) ; => '(42 a)


jesse.alama
2020-10-16 09:11:52

where’d you find that?


soegaard2
2020-10-16 09:12:22

Wrote it myself as a quick hack.


laurent.orseau
2020-10-16 09:17:03

You can simplify and make clearer with define-simple-macro: #lang racket (require syntax/parse/define) ; SYNTAX (store id ...) ; Make hashtable storing the values to which the ids are bound. ; The key is the symbol corresponding to the identifier. (define-simple-macro (store id:id ...) (make-hasheq (list (cons 'id id) ...))) ; SYNTAX (load ht (id ...)) ; Define the ids use initial values stored in the hash table. (define-simple-macro (load the-ht (id:id ...)) (begin (define ht the-ht) (define id (hash-ref ht 'id)) ...)) ;; Example (define x 42) (define y 'a) (define info (store x y)) info ; => '#hasheq((x . 42) (y . a)) (let () (load info (x y)) (list x y)) ; => '(42 a)


jesse.alama
2020-10-16 09:23:07

it kind of reminds me of a similar macro from Paul Graham’s On Lisp (my memory may be hazy)


soegaard2
2020-10-16 09:53:46

It’s a good idea to add :id. In general I am not too fond of define-simple-macro. I like to see the actual syntax transformer.


jesse.alama
2020-10-16 11:49:34

I’m heading over to the RacketCon Gather space



attilasedon1
2020-10-16 13:18:42

@attilasedon1 has joined the channel


rp
2020-10-16 13:20:20

Sorry to ask a simple question, but I’m struggling to follow the documentation for racket/system. I want to use an external unix command. I have the input in a racket string, and I want to be able to read the output as a bytestring. How do I do it? I feel it must be obvious, but it is the use of ports I think which is tripping me up. Do I have to setup all the ports separately, create a process and then correctly handle the ports in and out of the process?


jesse.alama
2020-10-16 13:53:22

@rp that’s right — you need to take care of the ports. Your input string can be turned into an input port; standard error and standard out could be new ports. Perhaps you could take a look at subprocess instead of system?


jesse.alama
2020-10-16 13:54:39

if you want to reuse your current processes’s stdout/stderr, you can use current-output-port and current-error-port


rp
2020-10-16 13:55:16

@jesse Thanks. And am I right in thinking that stdin is an output port whilst stdout and stderr are input ports? It’s kind of the wrong way round, but the right way round because stdout needs to be ready to get input from the process. Is that right?


jesse.alama
2020-10-16 13:56:04

that doesn’t sound right to me; stdin should be an input port, and the other two output ports


jesse.alama
2020-10-16 13:56:25

or do you need to switch things around somehow? (sorry if I’m getting you wrong)


rp
2020-10-16 13:57:26

I know I can do (with-output-to-string (lambda () (system “cmd”))), which allows me to get the output. However, that doesn’t help me put input in, so I think I need a full subprocess rather than using system (as you suggest).


rp
2020-10-16 13:57:26

Alright, I’ll fiddle with it more and see if I can work it out. Thanks for replying :slightly_smiling_face:


jesse.alama
2020-10-16 13:57:27

you might try using with-input-from-string or call-with-input-string to get your stdin set up


rp
2020-10-16 13:58:00

Oh! Can I use both with-output-to-string and with-input-from-string at the same time??


rp
2020-10-16 13:58:14

That would solve it for me. I’ll try that!


jesse.alama
2020-10-16 13:58:29

nice! good luck


rp
2020-10-16 14:03:40

Haha, it works. Its ugly (two nested lambda’s!) but it does seem to work. Thank you :slightly_smiling_face:


samdphillips
2020-10-16 16:20:17

Does anyone have, or know of, code that uses a canvas% and handles mouse-events for freehand drawing?


laurent.orseau
2020-10-16 16:21:38

IIRC, you just need to derive a class from canvas% and get the on-mouse events



samdphillips
2020-10-16 16:24:49

Yeah, I’m just trying to not reinvent it if possible.


laurent.orseau
2020-10-16 16:32:46

you should, in particular if the existing wheel is square :wink:


laurent.orseau
2020-10-16 17:05:21

Your wish is me wasting time :stuck_out_tongue: https://gist.github.com/Metaxal/0f928d1b429aa36b8c6046a77c994973


laurent.orseau
2020-10-16 17:06:24

(and yes, that’s a square wheel)


laurent.orseau
2020-10-16 17:10:50

now has a color picker!


laurent.orseau
2020-10-16 17:20:51

now with an undo button!


laurent.orseau
2020-10-16 18:08:46

Now with a line-width slider! @samdphillips


samdphillips
2020-10-16 19:29:18

Too much time on your hands :slightly_smiling_face:


spdegabrielle
2020-10-16 21:36:29

Nice ‘Virtual Biergarten’ ! It was really good to see so many Racketeers! see you all tomorrow


rokitna
2020-10-16 22:25:01

There’s someone I know who would probably love to see this code. Thanks for spending the time on it. :)


kellysmith12.21
2020-10-17 03:15:30

Is there a contract like cons/c but for streams?