Subject: Re: DEFSTRUCT Facility for Scheme (was Re: Java/Lisp Language Evolution Correlates)
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/06/19
Newsgroups: comp.lang.scheme
Message-ID: <8ijtc7$86fp$1@fido.engr.sgi.com>
Christopher Browne <cbbrowne@hex.net> wrote:
+---------------
| The idea of having keyword and optional arguments would be a very
| nice thing; it would allow diminishing the number of functions
| required to implement a system in Scheme...
+---------------

For optionals, at least, MzScheme has a neat "case-lambda" form
<URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node22.htm>:

	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'' -- e.g., the x in (lambda (a . x) ...) -- with a
	lambda expression. 
	...
	(define f
	  (case-lambda
	    [(x) x]
	    [(x y) (+ x y)]
	    [(a . any) a]))

	 (f 1) ; => 1
	 (f 1 2) ; => 3
	 (f 4 5 6 7) ; => 4
	 (f) ; raises exn:application:arity 


-Rob

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043