Re: Trouble trying to understand how low level macros interact with module system.
"Scott G. Miller" <[email protected]> Wed, 3 Dec 2008 12:06:05 -0600
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
What's probably happening here is a bad interaction between the module system and the low-level macro macro. define-macro is defined in terms of define-syntax. One of the things that a define-syntax macro does that a define-macro does not is manage the references to other definitions needed during the macro transformation. The (module ((some-macro some-binding))... form instructs the module system that the macro needs that binding to operate. In the case of define-macro though, I don't believe the reference to thefunc is rewritten to refer to the binding *inside the module*. define-macro is pretty simple in that respect, and just spits out an s-expression based on your definition, with little or no rewriting. 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=/