In article <firstname.lastname@example.org>,
Kent M Pitman <email@example.com> wrote:
| Tim Bradshaw <firstname.lastname@example.org> writes:
| > Also I have no idea if supplied-p parameters are supported in other
| > Lisps, though that may not be a big issue.
| Well, in scheme for example:
| (define (foo arg1 . maybe-arg2)
| (if (cdr maybe-arg2) ;supplied-p
| ... (car maybe-arg2) ... ;i.e., definitely-arg2
I think you probably meant something like this:
(define (foo arg1 . maybe-arg2)
(if (not (null? maybe-arg2)) ;supplied-p
... (car maybe-arg2) ... ;i.e., definitely-arg2
| It can often be glossed, in other words,. But it's ugly.
Indeed. I often find myself writing destructuring macros to help out.
By the way, some Schemes have a construct called "case-lambda":
The case-lambda form creates a procedure that dispatches to a
particular body of expressions based on the number of arguments
it receives. This provides a mechanism for creating variable-arity
procedures with more control and efficiency than using a ``rest arg''.
So using case-lambda, the above example [extended slightly] becomes:
((arg1) ...what to do if only one arg given...)
((arg1 arg2) ...what to do if exactly two args...)
((arg1 arg2 arg3 . the-remainder) ...three or more...)))
Rob Warnock, 8L-855 email@example.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA