[racket] Need help with macro...

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Feb 12 15:40:05 EST 2012

Have you considered using this kind of macro: 

#lang racket

(define-syntax ==> 
  (syntax-rules ()
    [(_ (it) one) one]
    [(_ (it) one two ...) (let ((it one)) (==> (it) two ...))]))

(==> (it) (+ 1 1) (+ it 1) (+ it it))

(define mult *)

(==> (it) (* 1 1) (* it 1) (* it it))

On Feb 12, 2012, at 3: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.
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

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

Posted on the users mailing list.