Home > Archive > Scheme > October 2004 > define-macro in MIT-Scheme ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
define-macro in MIT-Scheme ?
|
|
| Phoenix 2004-10-28, 8:58 am |
| Hello,
I am using MIT-Scheme and reading "Teach Yourself Scheme in Fixnum Days "
So I wanno knowing how to using "define-macro" in MIT-Scheme .
Anyone can tell me how to define "define-macro" by "define-syntax" ? thanks
....
| |
| Ray Dillinger 2004-10-28, 4:00 pm |
| Phoenix wrote:
> Hello,
> I am using MIT-Scheme and reading "Teach Yourself Scheme in Fixnum Days "
> So I wanno knowing how to using "define-macro" in MIT-Scheme .
> Anyone can tell me how to define "define-macro" by "define-syntax" ? thanks
> ...
It cannot be done. Define-syntax enforces hygiene absolutely.
Define-macro can specifically break hygiene.
Bear
| |
| Psy-Kosh 2004-10-28, 4:00 pm |
| >> Hello,
>
>
> It cannot be done. Define-syntax enforces hygiene absolutely.
> Define-macro can specifically break hygiene.
>
Directly quoting from "...fixnum days":
In MIT Scheme [26] version 7.7.1 and later, this is written as:
(define-syntax MACRO-NAME
(rsc-macro-transformer
(let ((xfmr (lambda MACRO-ARGS MACRO-BODY ...)))
(lambda (e r)
(apply xfmr (cdr e))))))
In older versions of MIT Scheme:
(syntax-table-define system-global-syntax-table 'MACRO-NAME
(macro MACRO-ARGS
MACRO-BODY ...))
Psy-Kosh
| |
| Psy-Kosh 2004-10-28, 4:00 pm |
| >
> It cannot be done. Define-syntax enforces hygiene absolutely.
> Define-macro can specifically break hygiene.
>
Also, I think what you meant to say is that syntax-rules enforces
hygene. define-syntax is just the thingie that says "bind the
transformer to this identifier as a macro", right?
(though, technically you can kinda mess with hygene even with
syntax-rules..... just that it takes a bit of effort. (petrofsky(sp)
extraction))
Psy-Kosh
| |
| Taylor Campbell 2004-10-28, 4:00 pm |
| Ray Dillinger <bear@sonic.net> wrote in message news:<cH7gd.1752$_3.24330@typhoon.sonic.net>...
> Phoenix wrote:
>
> It cannot be done. Define-syntax enforces hygiene absolutely.
> Define-macro can specifically break hygiene.
This is wrong. DEFINE-SYNTAX is merely a special form for introducing
macro transformers in Scheme. MIT Scheme supports several different
macro _systems_, such as SYNTAX-RULES, syntactic closures, and explicit
renaming. Only SYNTAX-RULES _enforces_ hygiene; the latter two allow
more general manipulation of it. An equivalent of
(define-macro (m x y . z) ...)
in MIT Scheme could be
(define-syntax m
(er-macro-transformer
(lambda (form rename compare)
(let ((x (cadr form))
(y (caddr form))
(z (cdddr form)))
...))))
ER-MACRO-TRANSFORMER means 'explicit renaming transformer'; all names
to be hygienically renamed in the output form must be constructed by
calling the RENAME procedure. Since you don't care for hygiene (note,
though, that this is dangerous, and you really ought to look into
learning about hygiene, even if TYSIFD doesn't explain it), you just
don't call RENAME in the output form. There are other ways to do it,
with the other macro system, syntactic closures, but it makes very
little difference if you're not going to use hygiene.
|
|
|
|
|