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
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
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
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
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))]))
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)]
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
`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
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
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
10 matches
Mail list logo