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

Re: (OPTIONAL ...) &RELATED-ISSUES



As to "stickiness" of OPTIONAL, what LSB does is to not interpret what
looks like a required arg any differently when it follows an optional
arg, EXCEPT to say it is optional.  So the syntax doesn't really suffer,
other than that if you want to specify a default value or supplied-p
var you have to say OPTIONAL again:
(define-public-routine (foo a (optional b) c (any-number-of frobs))
    ...)
==>
(define-public-routine (foo a (optional b) (optional c) (any-number-of frobs))
    ...)
One can also meaningfully have different type wrappers both "inside" and
"outside" what we call the call-mapping-keywords (eg OPTIONAL):
  (foo a b (vector (any-number-of (fixnum frobs) number-of-frobs)))
which says that the variable FROBS is of type VECTOR (and presumably
should be implemented thusly), but the ARGUMENTS which map into the
parameter FROBS are FIXNUMs.  NUMBER-OF-FROBS gets bound to just that,
and is automagically declared FIXNUM.  In LSB it actually works
to have this split-typing for OPTIONAL args too;
(define-public-routine (foo a (notype (optional (fixnum b) 'ugh))) ...)
which says that the second argument to FOO, if given, MUST be a FIXNUM.
But the variable B is NOTYPE, and might be bound to UGH.  I don't think
this last grotesquery has ever been used, but it sort of follows from the
way these things are interpreted.
   I am not advocating that any of this should be put into DEFUN.  The
LSB formalism considers DEFUN to be low-level and pretty implementation
dependent (think of pdl-vectors, pdl-lists).  What one does in LSB is to
describe what a "call" to a routine should be like, and how that call
maps into the bindings of the parameters.  Given
(define-public-routine (foo x (optional y)) ...),
whether the mapping from (foo a) => (lambda (x y) ...) is made at compile
or run time is left to LSB, since it can then make a reasonable default
choice based on the particuclar lisp implementation.  In the same way,
one can suppress evaluation of selected arguments without defining a fexpr
(define-public-routine (my-status (quoted kwd) (any-number-of other-frobs)) ...)
and a call to MY-STATUS will compile correctly (assuming of course no
calls to EVAL).