[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Are generated toplevel definitions secret?



On Sun 24 Apr 2011 02:14, Andre van Tonder <andre@x> writes:

> R5RS didn't specify this, which was always a very annoying obstacle to 
> portability.  E.g.,
>
>     (define x 1)
>     (let-syntax ((foo (lambda (e)
>                         (syntax (begin
>                                   (define x 2)
>                                   x)))))
>       (foo))  ;==> 2
>     x         ;==> NOT SPECIFIED IF IT SHOULD BE 1 or 2
>
> It seems from my reading on p. 15 that R7RS doesn't specify it either.
>
> In otehr words, definitions introduced in macros can possibly shadow toplevel 
> bindings, which is a major obstacle to safe hygienic macro programming.

How does this relate to modules and separate compilation?  I haven't
figured out a good way to implement this yet.

For example, in a.scm you have:

    (module (a)
      (export x y)
      (begin
        (define-syntax define-constant
          (syntax-rules ()
            ((_ var init)
             (begin
               (define val init)
               (define-syntax var (identifier-syntax val))))))

        (define-constant x 10)
        (define-constant y 20)))

Then in b.scm you have:

    (module (b)
      (import (a))
      (begin
        (display x) (newline)
        (display y) (newline)))

So let's say you compile a.scm to a.so, and then b.scm to b.so.  The
`begin' in module A expands to something like:

    (begin
      (define val-1098321098 10)
      (define-syntax x (identifier-syntax val-1098321098))
      (define val-1243098329 20)
      (define-syntax y (identifier-syntax val-1243098329))

The numbers indicate some attempt at producing a globally-unique
gensym, to preserve hygiene.

But then if you recompile a.scm, to a.so, you would have to generate the
same gensyms, or b.so will fail to link when it is loaded later -- so
the gensyms aren't quite random...

Guile does not currently introduce hygienic bindings for introduced
toplevel identifiers, for this reason.  I think it's the same in
Chicken's case, but they can tell you more about that.

See also:

    http://thread.gmane.org/gmane.lisp.guile.devel/11722
    http://thread.gmane.org/gmane.lisp.guile.devel/12244

I would be happy to implement this behavior if I knew how.  As it is, we
need to treat introduced names as API, which means that we can't
uniquify them.

Andy
-- 
http://wingolog.org/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports