Re: Trouble trying to understand how low level macros interact with module system.

"Igor Hjelmstrom Vinhas Ribeiro" <[email protected]> Wed, 3 Dec 2008 14:24:42 -0500
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
--===============6578739076381607992==
Content-Type: multipart/alternative; 
	boundary="----=_Part_13949_10860805.1228332282354"

------=_Part_13949_10860805.1228332282354
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello!

Scott,

   First of all, thanks for the reply!

Second,

On Wed, Dec 3, 2008 at 13:06, Scott G. Miller <[email protected]> wrote:

> 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.


   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?

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
>

------=_Part_13949_10860805.1228332282354
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello!<br><br>Scott,<br><br>&nbsp;&nbsp; First of all, thanks for the reply!<br><br>Second,<br><br><div class="gmail_quote">On Wed, Dec 3, 2008 at 13:06, Scott G. Miller <span dir="ltr">&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">What&#39;s probably happening here is a bad interaction between the module<br>
system and the low-level macro macro. &nbsp;define-macro is defined in<br>
terms of define-syntax. &nbsp;One of the things that a define-syntax macro<br>
does that a define-macro does not is manage the references to other<br>
definitions needed during the macro transformation.<br>
<br>
The (module ((some-macro some-binding))... form instructs the module<br>
system that the macro needs that binding to operate. &nbsp;In the case of<br>
define-macro though, I don&#39;t believe the reference to thefunc is<br>
rewritten to refer to the binding *inside the module*. &nbsp;define-macro<br>
is pretty simple in that respect, and just spits out an s-expression<br>
based on your definition, with little or no rewriting.</blockquote><div>&nbsp;</div><div>&nbsp;&nbsp; That&#39;s approximately what I would expect. But what I don&#39;t understand is<br>why this s-expression that was created is not able to use the &quot;thefunc&quot; (since<br>

it is defined in the environment in which I am executing it).<br><br>&nbsp;&nbsp; To put it another way: I would expect that the expression resulting from the<br>macro call &quot;(thefunc)&quot; would be executed in the exact same way (and in<br>

the exact same environment) as if I had typed &quot;(thefunc)&quot; - so it would work,<br>even though it is executing outside the module context...<br><br>&nbsp;&nbsp; However, when I type (thefunc) it works, but when the macro &quot;types it&quot; it<br>
doesn&#39;t. I was considering the macro would either execute in the context of<br>the module (and it would work) or in the same context I am typing (and it<br>would also work)... if that is not the case, in which context is it executing?<br>
<br>Regards,<br>&nbsp;Igor.<br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div>
On Sun, Nov 30, 2008 at 6:44 AM, Igor Hjelmstrom Vinhas Ribeiro<br>
&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt; wrote:<br>
&gt; Hello, Mike - thanks for the reply!<br>
&gt;<br>
&gt; &nbsp; &nbsp;Unfortunately, however, this also doesn&#39;t work[1]:<br>
&gt;<br>
&gt; &nbsp; &nbsp;Any other clue on what could be wrong?<br>
&gt;<br>
&gt; Regards,<br>
&gt; &nbsp;Igor.<br>
&gt;<br>
&gt; [1]. See below - trying Mike&#39;s suggestion. As before, calls to<br>
&gt; amacro fail stating that thefunc is undefined, while direct calls<br>
&gt; to thefunc work just fine.<br>
&gt;<br>
&gt; SISC (1.16.6)<br>
&gt; #;&gt; (max-stack-trace-depth 16)<br>
&gt; 0<br>
&gt; #;&gt;<br>
</div><div><div></div><div>&gt; #;&gt; (amacro)<br>
&gt; Error: undefined variable &#39;thefunc&#39;.<br>
&gt; ---------------------------<br>
&gt; Some stack trace entries may have been suppressed. To see all entries set<br>
&gt; the dynamic parameter suppressed-stack-trace-source-kinds to &#39;().<br>
&gt; #;&gt; (thefunc)<br>
&gt;<br>
&gt;<br>
&gt; ---<br>
&gt;<br>
&gt; #;&gt;<br>
&gt;<br>
&gt; On Sat, Nov 29, 2008 at 23:53, Mike J. Bell &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Try:<br>
&gt;&gt;<br>
&gt;&gt; (module ((thefunc) (amacro thefunc))<br>
&gt;&gt; &nbsp; (define-macro amacro (lambda () (thefunc)))<br>
&gt;&gt; &nbsp; (define (thefunc) (display &quot;\n\n---\n\n&quot;)))<br>
&gt;&gt;<br>
&gt;&gt; This (I think) means make an anonymous module with two exported symbols,<br>
&gt;&gt; thefunc and amacro (which depends on thefunc).<br>
&gt;&gt;<br>
&gt;&gt; Somebody else can I&#39;m sure give you a better theoretical reason why this<br>
&gt;&gt; works (and what it really means, and why yours does what it does, which<br>
&gt;&gt; isn&#39;t very intuitive to me off hand).<br>
&gt;&gt;<br>
&gt;&gt; Mike<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Nov 29, 2008 at 8:02 PM, Igor Hjelmstrom Vinhas Ribeiro<br>
&gt;&gt; &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hello!<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;I am trying to understand how the module system used by SISC<br>
&gt;&gt;&gt; interacts with the low-level macros that SISC supports.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; Specifically, I am trying to figure out why the follow snippet of<br>
&gt;&gt;&gt; &nbsp; code, an anonymous module that exports amacro and thefunc,<br>
&gt;&gt;&gt; &nbsp; doesn&#39;t work.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;(module (amacro thefunc)<br>
&gt;&gt;&gt; &nbsp; &nbsp; &nbsp;(define-macro amacro (lambda () (thefunc)))<br>
&gt;&gt;&gt; &nbsp; &nbsp; &nbsp;(define (thefunc) (display &quot;\n\n===\n\n&quot;)))<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; After I pasted it in the REPL, when I call (amacro) I get:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;#;&gt; (amacro)<br>
&gt;&gt;&gt; &nbsp; &nbsp;Error: undefined variable &#39;thefunc&#39;.<br>
&gt;&gt;&gt; &nbsp; &nbsp;console:16:7: &lt;indeterminate call&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; Curiously, if I just go ahead and type (thefunc) it works:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;#;&gt; (thefunc)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;===<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;#;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;Is anyone able to explain to me why this happens?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Regards,<br>
&gt;&gt;&gt; &nbsp;Igor.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -------------------------------------------------------------------------<br>
&gt;&gt;&gt; This SF.Net email is sponsored by the Moblin Your Move Developer&#39;s<br>
&gt;&gt;&gt; challenge<br>
&gt;&gt;&gt; Build the coolest Linux based applications with Moblin SDK &amp; win great<br>
&gt;&gt;&gt; prizes<br>
&gt;&gt;&gt; Grand prize is a trip for two to an Open Source event anywhere in the<br>
&gt;&gt;&gt; world<br>
&gt;&gt;&gt; <a href="http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/</a><br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Sisc-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:[email protected]" target="_blank">[email protected]</a><br>
&gt;&gt;&gt; <a href="https://lists.sourceforge.net/lists/listinfo/sisc-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/sisc-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Mike J. Bell on gmail<br>
&gt;<br>
&gt;<br>
&gt; -------------------------------------------------------------------------<br>
&gt; This SF.Net email is sponsored by the Moblin Your Move Developer&#39;s challenge<br>
&gt; Build the coolest Linux based applications with Moblin SDK &amp; win great<br>
&gt; prizes<br>
&gt; Grand prize is a trip for two to an Open Source event anywhere in the world<br>
&gt; <a href="http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/</a><br>
&gt; _______________________________________________<br>
&gt; Sisc-users mailing list<br>
&gt; <a href="mailto:[email protected]" target="_blank">[email protected]</a><br>
&gt; <a href="https://lists.sourceforge.net/lists/listinfo/sisc-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/sisc-users</a><br>
&gt;<br>
&gt;<br>
<br>
-------------------------------------------------------------------------<br>
This SF.Net email is sponsored by the Moblin Your Move Developer&#39;s challenge<br>
Build the coolest Linux based applications with Moblin SDK &amp; win great prizes<br>
Grand prize is a trip for two to an Open Source event anywhere in the world<br>
<a href="http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/</a><br>
_______________________________________________<br>
Sisc-users mailing list<br>
<a href="mailto:[email protected]" target="_blank">[email protected]</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/sisc-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/sisc-users</a><br>
</div></div></blockquote></div><br>

------=_Part_13949_10860805.1228332282354--


--===============6578739076381607992==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
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=/
--===============6578739076381607992==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Sisc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sisc-users

--===============6578739076381607992==--