[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why a new lexical form?



> From: bear <bear@xxxxxxxxx>
> On Wed, 5 Jun 2002, Al Petrofsky wrote:
> >> From: bear <bear@xxxxxxxxx>
> >>
> >> 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