Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread zeRusski
Luke, thanks. You were the first to get there and somehow I missed your reply :( On Friday, 19 April 2019 22:31:41 UTC+1, luke.whittlesey wrote: > > `identifier-binding` might be useful if a binding can be defined outside > of set/define > > > https://docs.racket-lang.org/reference/stxcmp.html?q

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Matthias Felleisen
Yes, I wanted to recall this trick for you and overshot :) > On Apr 19, 2019, at 6:04 PM, zeRusski wrote: > > Matthias, FWIW your first solution gave me a flashback from last year's > Summer School. I remember using this trick. Now I hope I don't forget when I > actually need it. > > Than

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread zeRusski
Matthias, FWIW your first solution gave me a flashback from last year's Summer School. I remember using this trick. Now I hope I don't forget when I actually need it. Thank you Michael and Matthias -- You received this message because you are subscribed to the Google Groups "Racket Users" gr

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread zeRusski
On Friday, 19 April 2019 22:39:10 UTC+1, Michael Murdock MacLeod wrote: > > I'm in no ways a macro expert, but will this work? It uses > identifier-binding > to check if the identifier for the hash table is bound. > Yep, looks like the winner. I should've inferred from the fact that "unbound

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Matthias Felleisen
I should have know better: (define-syntax (set/define stx) (syntax-case stx () [(_ id key val) (identifier-binding #'id) #`(begin (hash-set! h 'key val) h)] [(_ id key val) #'(begin (define id (make-hash)) (set/define id key val))]))

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Michael Murdock MacLeod
I'm in no ways a macro expert, but will this work? It uses identifier-binding to check if the identifier for the hash table is bound. (define-syntax (set/define stx) (syntax-case stx () [(_ ht key value) (cond [(identifier-binding #'ht) #'(hash-set! ht key value)]

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread zeRusski
Not quite what I had in mind. The following examples must all work without errors: #lang racket ;; set/define defined here (set/define h a 1) (set/define h a 2) (hash-set! h 'b 42) (define bar (make-hash)) (set/define bar a 1) (define (foo) (set/define local-h a 1) (set/define local-h a 2

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Luke Whittlesey
`identifier-binding` might be useful if a binding can be defined outside of set/define https://docs.racket-lang.org/reference/stxcmp.html?q=identifier-binding#%28def._%28%28quote._~23~25kernel%29._identifier-binding%29%29 On Fri, Apr 19, 2019 at 4:55 PM Matthias Felleisen wrote: > > I had the i

Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Matthias Felleisen
I had the impression that you want to create the hashtable when it’s not there and use it when it is: #lang racket (define-syntax (set/define stx) (syntax-case stx () [(_ id key val) (syntax-local-value #'id (lambda () #f)) (with-syntax ([h (car (syntax-local-value #'id (lambda

[racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread zeRusski
Here's what I've been trying and failing to do in Racket. The smallest example I could think of is a macro that sets a key in a hash-table, so basically this transformation: (set/define ht 'key 42) ;; => (hash-set! ht 'key 42) but if ht there is an unbound identifier it must bind it to a