Re: suggestion: a shorter convenience form
Per Bothner 25 Jun 2006 14:27 UTC
Jens Axel Søgaard wrote:
> I assume the standard boiler plate you are thinking
> of is
>
> (define-syntax foo
> (lambda (stx)
> (syntax-case stx ()
> <clauses>)))
> ?
Yes.
> a common extension to define-syntax is
>
> (define-syntax (foo stx)
> == (define-syntax foo (lambda (stx) ...))
>
> The "standard boiler plate" then becomes
>
> (define-syntax (foo stx)
> (syntax-case stx ()
> <clauses>))
>
> This is almost as short as your convenience macro
This has one extra longish keyword, an extra parameter name
mentioned twice, and an extra level of nesting/indentation.
> and at
> the same time still makes it possible to refer to the original
> input syntax-object of the transformer.
This seems to work:
(define-syntax-case name literals
(form expression))
For example:
(define-syntax-case foo ()
(form #`(quote form)))
Of course this isn't any better than your "common extension",
but it's not noticeably worse. And it does allow convenient
pattern-matching, about as convenient and compact as Common Lisp's
defmacro, but allowing multiple "cases".
> Refering to the
> original piece of syntax is often neccessary in order to give
> error messages in terms of user written syntax.
> I agree with you that the common case should be convenient
> to write, in this case I'm not sure I think it is worth
> introducing an extra binding form in order to save relatively
> few key strokes.
It's not the number of keystrokes that matter, it's the number
of tokens. Each token adds to the cognitive load required to
read a definition. A programmer familiar with the idiom can
abstract way the boiler-plate fairly easily, but it is still
an extra required but useless mental step.
--
--Per Bothner
xxxxxx@bothner.com http://per.bothner.com/