On Tue 24 May 2011 23:10, Andy Wingo <wingo@x
> (define-syntax define-const
> (syntax-rules ()
> ((_ name val)
> (define t val)
> (define-syntax name (syntax-rules () ((_) t)))))))
>> random name -- it needs to be predictable.
> Guile currently does not make the generated toplevel definition "t" have
> a fresh name. It would be nice if it could but it can't be a really
>FWIW, I have implemented this in Guile's master branch.
> Well why not have the name of "t" be "t" plus some string which depends
> only on the incoming form -- like its hash value. (Or the outgoing
> form; the considerations are different but similar.)
> That way you do preserve the "compatible recompilation" aspect, trading
> off true secrecy, but hey. Oh well.
> (define-const foo 10)
$1 = 10
> (define-const bar 20)
Here I used tab completion to show me the available bindings.
$2 = 20
The appended uniquifiers are derived from the hash of the stripped
definition form, i.e. `(define t 10)'. This means that there are still
some situations in which two bindings will collide -- as in:
(syntax-rules () (begin
((_ name val)
(define t val) ((_ v) (set! t v))))))))
(define-variable foo 10)
(define-variable bar 10)
(foo) => 20
I'm not really sure what the right thing is to do here.