[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #f = #none ?

> From: Bob Kerns <rwk@crl.dec.com>
>     Date: Thu, 19 Nov 92 10:18:44 EST
>     From: samp@kurz-ai.com (Sam Pilato)
>        (multiple-value-call #'foo
>          (if frob-p
>     	 (values :frob frob-val)
>     	 (values))
>          :blech bletch-val)
>     I agree with Fry.  I would much prefer being able to:
>     (foo :frob  (if frob-p frob-val <use-the-default-value>)
>          :blech bletch-val)

In my experience with common lisp, I have often wished for a value
that could be conventionally used to indicate "the default".  Often
NIL ends up being used that way (but suffers from the usual punning
problems).  For example, I have run into the following sort of
construct a number of times:

    (define-method my-method (#rest args #key thing)
      (apply fubar-1 thing: <use-the-default> another-thing: ... args))

Without some way to specify "use the default value for THING" one
either has to know what value to assign to THING, or operate on the
rest list.

Another, perhaps more important, advantage of allowing #none is that
is simplifies the semantics of default value assignment.  We could
define the defaulting semantics for keyword arguments as follows:

    (define-method my-method (#key ((a1 t1) v1) ((a2 t2) v2) ...)
	... stuff ...)


    (define-method my-method (#key pa1 pa2 ...)
       (bind (((a1 t1) (if (eq pa1 #none) v1 pa1))
              ((a2 t2) (if (eq pa2 #none) v2 pa2))
         ... stuff ...))

> I wasn't disagreeing with Fry.  But I would not like there
> to be some distinguished value which could not be passed
> in, because it would be interpreted as "use the default value".
> What if you remodularize your code, so that the appropriate
> place to do the defaulting is not in that function, but instead
> in a function three levels of call down?

Why is that a problem?  Under the semantics I gave above, #none is a
perfectly good value.  If no default is given, it is passed right
through and the "right" thing would happen at the fuction that was
prepared to do the defaulting.

> The multiple-value-call construct has the correct semantics.
> The syntax is awkward.  However, you can package it up in
> macros:
> (defaulting foo :frob (if frob-p frob-val :use-default)
>                 :blech bletch-val).

-- Jim Mayer
                                        Phone: (716) 422-9407
Webster Research Center                 Intelnet phone: 8*222-9407
Xerox Corporation                       Internet Email: mayer@wrc.xerox.com
800 Phillips Road, 0128-29E             XNS Email: James L Mayer:Wbst128:xerox
Webster, New York 14580                 Facsimile: (716) 265-7133