[plt-scheme] procedure instrospection

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Apr 18 04:19:45 EDT 2009

On Apr 18, Jose A. Ortega Ruiz wrote:
> Eli Barzilay <eli at barzilay.org> writes:
> 
> > But it does point at yet another problem -- what are the argument
> > names you'd expect for this:
> >
> >   (define foo
> >     (case-lambda [(x)   "stuff"]
> >                  [(a b) "other stuff"]))
> >
> > ?
> 
> (foo x #:optional y) 
> (foo x [y])
> 
> or something similar (i'm using the first form in my emacs thing for
> other schemes).

But the name for the "optional" in the above is `b'...  I've put
"optional" in quotes since it doesn't have to be an optional argument,
it can be anything, and can have behavior that is not related to the
other cases in the `case-lambda' form (that's why I used different
strings in the above).  The resulting arities can also be arbitrary,
for example:

  (case-lambda [(x) 1]
               [(a b c) 2]
               [(i j k l m) 3])

has an arity list of (1 3 5), which cannot be described with such an
`#:optional'.

Here's another random example from the texpict collection:

  (define inset/clip
    (case-lambda
     [(p l t r b) ...]
     [(p h v) (inset/clip p h v h v)]
     [(p a)   (inset/clip p a a a a)]))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.