[racket] Newbie question: Teach Yourself Scheme in Fixnum Days - macros

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Mar 30 09:10:17 EDT 2011

2011/3/30 John Sampson <jrs.idx at ntlworld.com>:
> Hello -
>
> I am going through TYSIFD which is said to be compatible with mzScheme.
>
> Descriptions of macros seem to be different depending which book one reads.
> TYSIFD advises the reader to 'require' the defmacro library
> - '(require (lib "defmacro.rkt"))' when using Racket (I assume) - and gives
> the example
>
> (define-macro  when
>  (lambda  (test  .branch)
>    (list  'if  test
>      (cons  'begin  branch))))

Way back in the olden days  define-macro  was a popular way to define macros.
Back then  define-syntax  had not yet been invented.
TYSIFD is slightly old so when it was written it made sense to use
define-macro.
Today I am sure the author would have chosen  define-syntax.
Now it ought to be possible to get the programs in the macro section
running in MzScheme,
since it is reasonable straightforward to write define-macro in terms
of define-syntax.
That is, the incantation (require (lib "defmacro.rkt")) makes
define-macro available to you.
But macros written with the help of define-macro is integrated as well
as define-syntax
in DrScheme/DrRacket.

To make a long story short:  Skip the macro section in TYSIFD (it is
simply too old)
and read the racket guide on macros.

-- 
Jens Axel Søgaard



Posted on the users mailing list.