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

Re: destructuring within "argument" positions

Commentary and BNF for Bound-variable-lists ocasioned by ALAN's note
below, and all the other notes flaming around this issue.
    Date: 30 September 1980 03:36-EDT
    From: Alan Bawden <ALAN at MIT-MC>
    Subject: destructuring and &mumbles
    .  .  .
    As the person who first combined destructuring and &mumbles in
    defmacro, let me tell you what I thought I was doing:
    .  .  .
    I don't think that &mumbles and destructuring combine to make any kind
    of reasonable pattern matcher.  If the interaction had turned out to
    be amazingly elegant, then perhaps we would have moved the combined
    mess back into defun, but it ISN'T.  In defmacro you frequently want
    BOTH features, but in defun you rarely need destructuring so there is
    no reason to clutter it up.
"destructuring" and &mumbles are independent features of a bound
variable list, and it is a sad commentary that two years after the
consistent and simple notion of "pattern-matching-destructuring" for
argument positions was introduced, there still has to be flaming
about it ("elegant" in DEFMACRO, but "kludgy" in DEFUN -- really?)
Admittedly, there is an alternate proposal for destructuring" -- RMS's
idea of destructuring over programs rather than data forms -- but this
does not change the incredibly simple syntax for a DEFUN/DEFMACRO with
destructuring.  Leaving aside for the moment the &AUX as irrelevant,
and the potential for destructuring over Vectors in NIL, we can have
the following BNF-like definitions:

  <vsymbol> ::= any symbol usable as a variable (which excludes NIL 
		and T in MacLISP)

  <dvar>    ::= <vsymbol> | ( <dvar> . <dvar> ) 

  <ivar>    ::= <vsymbol> | ( <dvar> <form> ) | ( <dvar> <form> <vsymbol>) 

  <bvl>     ::= ( {<dvar>}* {&OPTIONAL {<ivar>}*1} {&REST <ivar>} )

The name <dvar> is for an argument position which is destructurable;
<ivar> is for a position which admits an initialization value when it 
is optionally not supplied (and also an optional "supplied-p" variable);
the construct {...}* means 0 or more repetitions of the construct within
brackets, and {...}*1 means 1 or more.  This definition for <bvl> is
adequete then for both DEFUN and DEFMACRO, with the additional
proviso that  (<item-1> ... <item-n> . <vsymbol>) is an additional
kind of destructuring for DEFMACRO, which coincidently happens to be
equivalent to  (<item-1> ... <item-n> &REST <vsymbol>).