Re: [Scheme-reports] Are generated toplevel definitions secret?
Peter Bex 24 Apr 2011 15:21 UTC
On Sun, Apr 24, 2011 at 05:15:12PM +0200, Andy Wingo wrote:
> On Sun 24 Apr 2011 16:57, Peter Bex <Peter.Bex@xs4all.nl> writes:
>
> > Chicken doesn't support identifier syntax, so it would show an error :)
>
> 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. The (x) macro simply expands to a#x
which accesses the correct x. (it does this through one extra layer of
gensym-indirection to prevent a bug with quote, but that's irrelevant to
the core idea)
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