[Scheme-reports] EVAL Andre van Tonder (23 Apr 2011 23:47 UTC)
[Scheme-reports] What happened to (UNQUOTE <expression> ...) Andre van Tonder (24 Apr 2011 00:04 UTC)
[Scheme-reports] Are generated toplevel definitions secret? Andre van Tonder (24 Apr 2011 00:15 UTC)
[Scheme-reports] COND, CASE, AND, ... macros are buggy Andre van Tonder (24 Apr 2011 00:24 UTC)
[Scheme-reports] Buggy definition of BEGIN Andre van Tonder (24 Apr 2011 00:33 UTC)
Re: [Scheme-reports] Buggy definition of BEGIN Jussi Piitulainen (24 Apr 2011 06:55 UTC)
[Scheme-reports] Restrictions on internal BEGIN? Andre van Tonder (24 Apr 2011 01:45 UTC)
Re: [Scheme-reports] Restrictions on internal BEGIN? Jussi Piitulainen (24 Apr 2011 07:20 UTC)
[Scheme-reports] Toplevel import scoping Andre van Tonder (24 Apr 2011 02:02 UTC)
Re: [Scheme-reports] Toplevel import scoping Alex Shinn (24 Apr 2011 02:44 UTC)
Re: [Scheme-reports] Toplevel import scoping Aaron W. Hsu (29 Apr 2011 17:11 UTC)
Re: [Scheme-reports] Toplevel import scoping Aaron W. Hsu (29 Apr 2011 17:10 UTC)
Re: [Scheme-reports] Are generated toplevel definitions secret? Peter Bex (24 Apr 2011 15:42 UTC)
Re: [Scheme-reports] Are generated toplevel definitions secret? Andre van Tonder (24 Apr 2011 15:53 UTC)
(missing)
(missing)
(missing)
Re: Are generated toplevel definitions secret? Aaron W. Hsu (24 May 2011 18:51 UTC)
(missing)
Re: [Scheme-reports] Are generated toplevel definitions secret? Perry E. Metzger (07 Nov 2011 18:40 UTC)
Re: [Scheme-reports] Are generated toplevel definitions secret? Perry E. Metzger (07 Nov 2011 18:45 UTC)
Re: [Scheme-reports] Are generated toplevel definitions secret? Sztefan Edwards (25 May 2011 14:32 UTC)
Re: Are generated toplevel definitions secret? Aaron W. Hsu (25 May 2011 20:03 UTC)
Re: [Scheme-reports] What happened to (UNQUOTE <expression> ...) Andre van Tonder (24 Apr 2011 03:10 UTC)
Re: [Scheme-reports] EVAL Alex Shinn (24 Apr 2011 02:10 UTC)
Re: [Scheme-reports] EVAL John Cowan (24 Apr 2011 06:56 UTC)

Re: [Scheme-reports] Are generated toplevel definitions secret? Peter Bex 24 Apr 2011 15:42 UTC

On Sun, Apr 24, 2011 at 05:21:30PM +0200, Peter Bex wrote:
> > Heh, cool.  Fortunately it's not central to my argument.  How about an
> > accessor macro:
> >
> >       (begin
> >         (define-syntax define-getter
> >           (syntax-rules ()
> >             ((_ var init)
> >              (begin
> >                (define val init)
> >                (define-syntax var
> >                  (syntax-rules ()
> >                    ((_) val)))))))
> >
> >         (define-getter x 10)
> >         (define-getter y 20))
> >
> > If I put that in a chicken module, import the module, then evaluate (x)
> > and (y), does that evaluate to 10 and 20, respectively?
>
> Yeah.  Each macro carries its syntactic information with it, like a
> closure.  So "val" in the macro expansion would refer to the x that is
> defined in that module.

I overlooked the fact that val is used, not var.  This will give an
error because the "val" is defined in a different phase than the "var"
macro is declared.

If I change (define val init) to (define-for-syntax val init), the
generated "var" macro will pick up on it.  Then it will use the same
"val" for both x and y, and hence it will overwrite the binding.
So it's basically the same as putting this in your module:

(define val 10)
(define val 20)

I'm not 100% sure but I suppose this could be considered a bug.

Cheers,
Peter
--
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
							-- Donald Knuth

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