[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
optional arguments
I have a different optional arguments proposal, which people should keep
in mind as an alternative:
Don't make any change to the syntax of LAMBDA. Instead, just introduce
a new special form for taking apart rest arguments. Example:
(LAMBDA (A B . R)
(OPTIONAL ((X 1) (Y (+ X 5))) R
-body-))
would be analogous to the Comon Lisp lambda-expression
(LAMBDA (A B &OPTIONAL (X 1) (Y (+ X 5)))
-body-),
and
(LAMBDA (A B . R)
(OPTIONAL ((X 1) (Y (+ X 5)) . R) R
-body-))
would be like
(LAMBDA (A B &OPTIONAL (X 1) (Y (+ X 5)) &REST R)
-body-),
I think this gets most of the benefits you want without making LAMBDA
hairy. It provides parameter list destructuring and error checking in a
nice orthogonal way, and is only a little bit more verbose than hairy
LAMBDA-isms. And it can be implemented in straightforwardly as a macro.
I have had this in the back of my mind since about 1981. I never got
around to installing it in T, but I should have. I have implemented and
used it on several occasions (e.g. for implementing R^2 Scheme in T),
and was fairly happy with it.
Effiency note: the mythical "sufficiently clever compiler" can avoid
consing the rest-list if there's only the one reference to R. I think
this would be a very straightforward transformation.
Jonathan