suggestion: a shorter convenience form Per Bothner (22 Jun 2006 19:42 UTC)
Re: suggestion: a shorter convenience form Jens Axel Søgaard (25 Jun 2006 08:14 UTC)
Re: suggestion: a shorter convenience form Per Bothner (25 Jun 2006 14:27 UTC)
Re: suggestion: a shorter convenience form Jens Axel Søgaard (25 Jun 2006 15:49 UTC)
Re: suggestion: a shorter convenience form Per Bothner (26 Jun 2006 23:56 UTC)
Re: suggestion: a shorter convenience form Jens Axel Søgaard (27 Jun 2006 09:00 UTC)
Re: suggestion: a shorter convenience form Per Bothner (27 Jun 2006 14:55 UTC)

Re: suggestion: a shorter convenience form Jens Axel Søgaard 24 Jun 2006 08:13 UTC

Per Bothner skrev:
> A problem with define-syntax+syntax-case is that you
> get very verbose syntax definitions, with lots of
> standard boiler-plate.  This makes syntax definitions
> needlessly hard to read and (less important) more tedious to
> write.  This has tempted some of my Kawa users to use the "legacy"
> non-hygienic define-macro form, even though I discourage it.
> Even plain R5RS define-syntax+syntax-rules is
> ridiculously verbose.
>
> One idea I had has this little conveniece macro:
>
> (define-syntax define-syntax-case
>    (syntax-rules ()
>      ((define-syntax-case name literals . parts)
>       (define-syntax name
>         (lambda form
>          (syntax-case form literals . parts))))))
>
> Typical use - especially nice if #` is availiable:
>
> (define-syntax-case NAME ()
>   ((_ PVAR ...)
>   #`(... PVAR ...))
>
> Of course people can define this themselves, but
> it is nicer if it is standard, because then people
> get used to reading it.

I assume the standard boiler plate you are thinking
of is

   (define-syntax foo
     (lambda (stx)
        (syntax-case stx ()
           <clauses>)))
?

In analogy with

      (define (foo x)
   == (define foo (lambda (stx) ...))

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 and at
the same time still makes it possible to refer to the original
input syntax-object of the transformer. 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.

--
Jens Axel Søgaard