[racket] Need help with macro...

From: Richard Cleis (rcleis at me.com)
Date: Sun Feb 12 16:22:17 EST 2012

On Feb 12, 2012, at 1:09 PM, FS Racket wrote:

> 
> 
> On Sun, Feb 12, 2012 at 1:34 PM, Richard Cleis <rcleis at me.com> wrote:
> The DrRacket interactions window replies with 48, not an error, when your syntax is defined in the definitions window, your function is defined in the interactions area, and the example is finally run in the interactions area.
> 
> How are you making it fail?
> 
> Also, have you attempted to use the Macro Stepper? Even if you aren't actually debugging the macro, it coerces you to organize your thoughts about how your code is organized (in this case, how the expansion relates to the word 'mult' and it's actual definition.)
> 
> rac
> 
> 
> Hi Richard,
> 
> Good questions.
> 
> The way my code is organized is that the macro is in its own file and installed as a collection in my personal library (i.e. the default location of personal collections).  I then create a new file, say "test.rkt", require the macro library file, and then define the function "mult".  Within this same file, I then add the code examples contained in my previous email.  Finally, I "run" the "test.rkt" file using the "Racket -> Run" menu option.
> 
> Yes, I have used the macro stepper; I should have mentioned that.  It's bizarre.  Prior to any expansion, all identifiers named 'mult' have an associated binding.  As I step through the expansion in the following code, the last 'mult' eventually loses its binding.  I don't know how or why.  
> 
> (==>
>  (mult 12 2)
>  (mult 2 _)
>  (mult _ 1))
> 
> Please let me know if any further clarification is needed.

In the example that doesn't work, the first mult is needed for another use of ==>. In the simpler examples, it is not. Notice that the orphaned mult occurs on the second step when another use is expanded, while in the simpler examples another use of ==> does not occur.  In the simple cases, mult is known to the expanded code; in the example that doesn't work, mult is not known to repeated use of the macro. Another clue is: if you run the test in the interactions window, it works because the definition of mult (in definitions) is automatically provided for interactions.

I haven't even read your macro; the amazing and amusing macro stepper knows all and tells all.

rac


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120212/9ddd39cb/attachment.html>

Posted on the users mailing list.