Re: Scheme macros
From: Anton van Straaten (anton_at_appsolutions.com)
Date: 02/20/04
- Next message: David Steuber: "Re: Who is using SBCL on OSX 10.3.2?"
- Previous message: mark: "Re: Advantages of Lisp?"
- In reply to: Jacek Generowicz: "Scheme macros"
- Next in thread: Pascal Costanza: "Re: Scheme macros"
- Reply: Pascal Costanza: "Re: Scheme macros"
- Reply: Grzegorz Chrupała: "Re: Scheme macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 20 Feb 2004 06:43:07 GMT
Jacek Generowicz wrote:
> [Don't want to start a flamefest, so I'm not crossposting this to
> c.l.s]
>
> In _Lambda: the ultimate "little language"_, Olin Shivers suggests
> (second paragraph of section 9) that " ... Scheme has the most
> sophisticated macro system of any language in this family ...", where
> 'this family' is explicitly stated to include Common Lisp.
>
> Now, I don't know much about the Scheme macro system ... my impression
> is that the main difference from CL's macros lies in Scheme's
> so-called hygiene, which I (mis?)understand to be a mechanism for
> preventing variable capture (which in CL is considered to be a
> feature, not a bug, of the macro system (particularly given that
> variable capture is less "problematic" in a Lisp-N, where N>1)).
>
> My question is ... how should I interpret the claim that Scheme's
> macro system is more "sophisticated" than CL's ? Does it merely reflect
> a preference for Scheme's "hygene", or is there something else behind
> the statement ?
It's not only hygiene. Like Barry, I would assume that Olin was talking
about the syntax-case macro system:
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?Syntax-Case
http://www.scheme.com/syntax-case/
http://www.scheme.com/tspl/syntax.html#./syntax:h3
Syntax-case is a rich system that's hard to summarize briefly, but I'll take
a stab at it. I've identified four key features below:
* Although syntax-case is a hygienic macro system, it allows you to
selectively break hygiene. This allows it to do the same kinds of things
defmacro can do, but from the opposite direction: you need to take special
action to break hygiene, rather than having to take action to preserve
hygiene. All things being equal, the syntax-case approach ought to be
preferable; but defmacro fans will tell you that all things aren't equal,
that syntax-case pays a price in terms of complexity.
* Syntax-case supports pattern-matching of syntax, but also supports use of
procedural code, as defmacro does.
* With syntax-case, uses of pattern variables or macro variables don't have
to be escaped in the same way as they do with defmacro, i.e. you get rid of
all the quasiquote, unquote, etc., along with the need to think about that
issue when writing macros. In a 9-line example on c.l.s. the other day[*],
a hygienic pattern-matching macro eliminated "two gensyms, one quasiquote,
six unquotes, and one unquote-splicing." The only time you really need to
think about issues related to escaping of variables is when breaking
hygiene, which is the exception rather than the rule.
* Syntax-case represents syntax using syntax objects with their own
specialized structure, rather than using ordinary lists, as defmacro does.
This is something of a tradeoff, which can be thought of as analogous to the
tradeoff that can arise in almost any Lisp program, when choosing between
implementing a data structure using only lists, or implementing it using
some kind of structure mechanism (defstruct, CLOS). The flexibility of
lists still has some advantages in some situations, but I don't know of
anyone who uses lists exclusively in real programs today. It can be argued
that a similar situation applies to macros, especially more complex ones:
using nothing but lists to manipulate syntax leads to exactly the same sort
of problems and limitations that you have when using nothing but lists to
manipulate an ordinary program's data; but using non-list structures also
loses some simplicity.
My own feeling is that it's useful to have access more than one macro
system. They all have a different flavor and have different pros and cons.
For example, although syntax-rules is the most restricted of these systems,
it makes for cleaner and simpler macros than defmacro, in many cases where a
purely hygienic macro is wanted. Happily, Lisp being the ultra-flexible
language that it is, anyone who wants to play with syntax-rules in CL can
take a look at:
http://www.ccs.neu.edu/home/dorai/mbe/mbe-lsp.html
Anton
[*]
http://groups.google.com/groups?selm=f0wWb.458%24hm4.393%40newsread3.news.at
l.earthlink.net
- Next message: David Steuber: "Re: Who is using SBCL on OSX 10.3.2?"
- Previous message: mark: "Re: Advantages of Lisp?"
- In reply to: Jacek Generowicz: "Scheme macros"
- Next in thread: Pascal Costanza: "Re: Scheme macros"
- Reply: Pascal Costanza: "Re: Scheme macros"
- Reply: Grzegorz Chrupała: "Re: Scheme macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|