[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.



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
per@xxxxxxxxxxx   http://per.bothner.com/