Re: why a new lexical form?
Al Petrofsky 05 Jun 2002 20:12 UTC
> From: bear <xxxxxx@sonic.net>
> On Wed, 5 Jun 2002, Al Petrofsky wrote:
> >> From: bear <xxxxxx@sonic.net>
> >>
> >> Can't we just use a syntax definition and say
> >>
> >> (Comment ...)
> >>
> >> "expands" to nothing?
No.
With (define-syntax comment (syntax-rules () ((_ . x) (begin)))),
comments would only be usable at top-level and at the start of bodies.
With (define-syntax comment (syntax-rules () ((_ . x) 'comment))),
comments would be legal in any expression context, but would not work
between internal definitions. Neither version can be used for
commenting out parts of a literal inside a quote, or some arguments in
a procedure call, or a few binding clauses of a let, etc..
> I'm not getting it. How is this different from
>
> (define stuff
> '(foo
> bar
> (Comment FIXME: These two cause crashes for some reason -APP
> baz
> quux
> )
> zork))
For starters, that doesn't work because -app is an invalid token.
Secondly, (quote (foo bar)) evaluates to (foo bar), regardless of
foo's syntax binding: (quote (lambda 7)) => (lambda 7). In general,
special forms are passed their argument data as-is, rather than being
passed some evaluated or otherwise processed form of the data. That's
the point of special forms.
> I bring this up because anything that requires new tokens
> to be recognized by the lexer is inherently nonportable.
> It is either "there" or "not there" in a given system, and
> there's not much you can do about it.
Right. That's why the lisp standard includes reader macros as well as
expression macros.
(In this case, we're actually requiring a new intertoken space rather
than a new token, but that doesn't affect your point.)
-al