This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: optional parameters


   Cc: guile@cygnus.com
   From: Jim Blandy <jimb@red-bean.com>
   Date: 02 Oct 1998 14:11:01 -0500
   Sender: owner-guile@cygnus.com
   Precedence: bulk
   Content-Type: text
   Content-Length: 1135


   > It occured to me that since the scheme execution process checks the
   > number of arguments as it does the bindings of procedure arguments,
   > it could (in theory) also check their types and thus allow type-based
   > procedure call signatures like you get with java. Would this be at all
   > useful? Would it make compilation of scheme code impossible? I guess
   > it would be a pretty major extension to R4RS too.
   > 
   > Well, just an idea...

   I think Chez Scheme has an extension called case-lambda (or something
   like that) where you can do pattern-matching on the number and
   structure of the arguments:

   (case-lambda 
     ((a)   ... code to run when called with one argument ...)
     ((a b) ... code to run when called with two arguments ...)
     ...)

   I don't see any reason this couldn't be extended to:

   (case-lambda
     ((a) ... blah ...)
     ((a b) ... blah ...)
     ((a (b c ...)) ... second argument must be a list of at least one
			element, c is bound to its tail)
     (((number? a) b c) ... three arguments, the first of which must be
			    a number ...))

   Or something like that.  Don't shoot me over the syntax.

Andrew Wright's pattern matching code will do this.  If you can run
Aubrey Jaffer's slib, you can run the pattern matching code.  It
should compile well, too.  There's a link to it from the internet
Scheme Repository.

-- 
Clifford Beshers                     Computer Graphics and User Interfaces Lab
beshers@cs.columbia.edu                         Department of Computer Science
http://www.cs.columbia.edu/~beshers                        Columbia University