Subject: Re: eof-error-p/eof-value
From: (Rob Warnock)
Date: 1999/08/02
Newsgroups: comp.lang.lisp
Message-ID: <7o3q57$>
In article <>,
Kent M Pitman  <> wrote:
| Tim Bradshaw <> 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:

	(define foo
	    ((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
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA