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

Re: suggestion: a shorter convenience form

This page is part of the web mail archives of SRFI 93 from before July 7th, 2015. The new archives for SRFI 93 contain all messages, not just those from before July 7th, 2015.

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 ()

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 ()

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