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))]))


This isn’t exactly what you refer to with “is unbound at run-time” in other 
Lisps. 





> On Apr 19, 2019, at 5:33 PM, zeRusski <vladilen.ko...@gmail.com> wrote:
> 
> 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)
>   (hash-set! local-h 'b 42)
>   local-h)
> 
> (foo)
> 
> Basically, if the identifier h is unbound at runtime
>   (set/define h key val)
> is the same as
>  (define h (make-hash))
>  (hash-set! h 'key val)
> 
> If h is bound
>  (hash-set! h 'key val)
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com 
> <mailto:racket-users+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to