Re: Trouble trying to understand how low level macros interact with module system.
"Scott G. Miller" <[email protected]> Wed, 3 Dec 2008 13:59:42 -0600
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Dec 3, 2008 at 1:24 PM, Igor Hjelmstrom Vinhas Ribeiro <[email protected]> wrote: >> based on your definition, with little or no rewriting. > > > That's approximately what I would expect. But what I don't understand is > why this s-expression that was created is not able to use the "thefunc" > (since > it is defined in the environment in which I am executing it). > > To put it another way: I would expect that the expression resulting from > the > macro call "(thefunc)" would be executed in the exact same way (and in > the exact same environment) as if I had typed "(thefunc)" - so it would > work, > even though it is executing outside the module context... > > However, when I type (thefunc) it works, but when the macro "types it" it > doesn't. I was considering the macro would either execute in the context of > the module (and it would work) or in the same context I am typing (and it > would also work)... if that is not the case, in which context is it > executing? Well, if (thefunc) was defined in the top level, this should be true. However, (thefunc) defined in the module is actually bound to a gensym'ed symbol. So when the macro is invoked, and it produces a literal |thefunc| instead of the gensymed version, it fails. When you do it however, your expression is run through the syntax expander, and since the module is imported, your |thefunc| is renamed to the gensymed version and works. At least this is what I think is happening. :) Scott > > Regards, > Igor. > > >> >> On Sun, Nov 30, 2008 at 6:44 AM, Igor Hjelmstrom Vinhas Ribeiro >> <[email protected]> wrote: >> > Hello, Mike - thanks for the reply! >> > >> > Unfortunately, however, this also doesn't work[1]: >> > >> > Any other clue on what could be wrong? >> > >> > Regards, >> > Igor. >> > >> > [1]. See below - trying Mike's suggestion. As before, calls to >> > amacro fail stating that thefunc is undefined, while direct calls >> > to thefunc work just fine. >> > >> > SISC (1.16.6) >> > #;> (max-stack-trace-depth 16) >> > 0 >> > #;> >> > #;> (amacro) >> > Error: undefined variable 'thefunc'. >> > --------------------------- >> > Some stack trace entries may have been suppressed. To see all entries >> > set >> > the dynamic parameter suppressed-stack-trace-source-kinds to '(). >> > #;> (thefunc) >> > >> > >> > --- >> > >> > #;> >> > >> > On Sat, Nov 29, 2008 at 23:53, Mike J. Bell <[email protected]> wrote: >> >> >> >> Try: >> >> >> >> (module ((thefunc) (amacro thefunc)) >> >> (define-macro amacro (lambda () (thefunc))) >> >> (define (thefunc) (display "\n\n---\n\n"))) >> >> >> >> This (I think) means make an anonymous module with two exported >> >> symbols, >> >> thefunc and amacro (which depends on thefunc). >> >> >> >> Somebody else can I'm sure give you a better theoretical reason why >> >> this >> >> works (and what it really means, and why yours does what it does, which >> >> isn't very intuitive to me off hand). >> >> >> >> Mike >> >> >> >> >> >> On Sat, Nov 29, 2008 at 8:02 PM, Igor Hjelmstrom Vinhas Ribeiro >> >> <[email protected]> wrote: >> >>> >> >>> Hello! >> >>> >> >>> I am trying to understand how the module system used by SISC >> >>> interacts with the low-level macros that SISC supports. >> >>> >> >>> Specifically, I am trying to figure out why the follow snippet of >> >>> code, an anonymous module that exports amacro and thefunc, >> >>> doesn't work. >> >>> >> >>> (module (amacro thefunc) >> >>> (define-macro amacro (lambda () (thefunc))) >> >>> (define (thefunc) (display "\n\n===\n\n"))) >> >>> >> >>> After I pasted it in the REPL, when I call (amacro) I get: >> >>> >> >>> #;> (amacro) >> >>> Error: undefined variable 'thefunc'. >> >>> console:16:7: <indeterminate call> >> >>> >> >>> Curiously, if I just go ahead and type (thefunc) it works: >> >>> >> >>> #;> (thefunc) >> >>> >> >>> >> >>> === >> >>> >> >>> #;> >> >>> >> >>> Is anyone able to explain to me why this happens? >> >>> >> >>> Regards, >> >>> Igor. >> >>> >> >>> >> >>> ------------------------------------------------------------------------- >> >>> This SF.Net email is sponsored by the Moblin Your Move Developer's >> >>> challenge >> >>> Build the coolest Linux based applications with Moblin SDK & win great >> >>> prizes >> >>> Grand prize is a trip for two to an Open Source event anywhere in the >> >>> world >> >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> >>> _______________________________________________ >> >>> Sisc-users mailing list >> >>> [email protected] >> >>> https://lists.sourceforge.net/lists/listinfo/sisc-users >> >>> >> >> >> >> >> >> >> >> -- >> >> Mike J. Bell on gmail >> > >> > >> > >> > ------------------------------------------------------------------------- >> > This SF.Net email is sponsored by the Moblin Your Move Developer's >> > challenge >> > Build the coolest Linux based applications with Moblin SDK & win great >> > prizes >> > Grand prize is a trip for two to an Open Source event anywhere in the >> > world >> > http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> > _______________________________________________ >> > Sisc-users mailing list >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/sisc-users >> > >> > >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Sisc-users mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/sisc-users > > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/