chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] hygienic named let


From: felix winkelmann
Subject: Re: [Chicken-users] hygienic named let
Date: Mon, 1 Sep 2008 09:34:03 +0200

On Sun, Aug 31, 2008 at 7:28 AM, Jim Ursetto <address@hidden> wrote:
> There's a bit of a corner case I found with hygienic named let.
>
>     #;3> (module foo (bar)
>               (import scheme)
>               (define-syntax bar (syntax-rules ()
>                     ((_) (let loop ((x 3)) x)))))
>     #;4> (module baz () (import foo) (bar))
>     Warning: reference to possibly unbound identifier: loop
>     Warning: reference to possibly unbound identifier: letrec
>
> It seems that (in ##sys#expand-0, where LET is handled specially)
> LETREC is not seen as a macro, and is renamed like a regular
> identifier.  Yet this works perfectly for regular LET, direct LETREC,
> and even the chained example below:

Indeed, letrec is not detected to be a macro. The named let
expansion is somewhat special in that it is the only core
syntax that expands into the use of a macro. If that macro
is not in the current import environment, it is treated just
like a normal value-binding (and thus renamed).

>
>     #;10> (module foo (bar) (import scheme) (define-syntax bar
> (syntax-rules () ((_) (let ((x 3)) x)))))
>     #;12> (module baz (quux) (import foo) (define-syntax quux
> (syntax-rules () ((_) (bar)))))
>     #;13> (module xyzzy () (import baz) (quux))
>     3
>

xyzzy does not import "scheme", it doesn't know about letrec.

>
> My guess was that since LET wasn't a real macro, it had no environment
> in which to look up the LETREC.  I couldn't concoct one in
> ##sys#expand-0, so I commented out the special LET handling code there
> and just rewrote it as a regular macro, below.  Afterward, regular let
> continued to work fine, as did named let in normal circumstances.

Right - scheme is not imported, so there's no way to detect whether
letrec is a macro or not.

>
> Unfortunately, named let -still- didn't work in this corner case, even
> though the LETREC is renamed.  Also, if you rename anything else, it
> fails too --- for example, change ##core#app to ,(r 'apply), and you
> will get an unbound identifier APPLY.
>
> So, I am stumped for now.  Any ideas?
>

Named let is handled specially by the expander - redefinitions
of let will not help here (unless they exist in a surrounding local
binding environment). I have made letrec a core form, which
makes the named-let expansion independent of any macros.
The current HEAD in hygienic should work better, now. I'm not
sure about the 'apply thing as it works for me, if used
in a normal module-level macro.


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]