From: Joerg Hoehle
Subject: Re: argument passing: defaults
Date: 
Message-ID: <60rae5$7m3@omega.gmd.de>
SDS (···········@cctrading.com) wrote:
: Many people answered (thanks to everyone!) teaching me about 
: 	(&optional (arg default arg-given-p))
: (I did not know about the third thing, arg-given-p).

: Unfortunately, I have several arguments like that, so nested ifs are not
: a feasible solution. But, I guess, apply would do the trick:

: (defun zz (&key (ar1 ..) (ar2 ..) (ar3 ..)) ...)
: (defun xx (&key (ar1 nil ar1p) (ar2 nil ar1p) (ar3 nil ar3p))
:   (apply #'zz (nconc (if ar1p (list :ar1 ar1)) (if ar2p (list :ar2 ar2))
: 		     (if ar3p (list :ar3 ar3)))))

: Of course, this is suitable only is xx is not called too often - because
: of the extra consing. Or maybe not? You have to cons up the list of args
: for zz anyway, right?

If you don't want to cons much or waste time, better not use &key parameters.

Better use (zz a) and (zz) style forms, even though your code becomes
repetitive.  I also don't like this, but I've yet to find something
better than Lisp.

Maybe you should question yourself why you want to maintain an
&optional argument down to a bottom function?  Because only the bottom
function knows about a good default value?  Realize that Lisp doesn't
let you pass #<UNBOUND> around and use some other special indicator.

Regards,
	Jo"rg Ho"hle.
············@gmd.de		http://zeus.gmd.de/~hoehle/amiga-clisp.html

From: Kent M Pitman
Subject: Re: argument passing: defaults
Date: 
Message-ID: <sfw2026xzyf.fsf@world.std.com>
In article <··········@omega.gmd.de> ······@zeus.gmd.de (Joerg Hoehle) writes:

> ... If you don't want to cons much or waste time, better not use &key parameters.

This is an observation about particular implementations, not about the
language.  Keyword parameters are trouble when they are variable but
hardly anyone ever does (f key1 val1 key2 val2).  Mostly one does
(f :key1 val1 :key2 val2) in such a way that a compiler could allow
you the flexibility of keyword calling without the performance penalty
in a large number of cases.  Once in a while one does (apply #'f args)
and there really is a problem but it's obvious in that case that just 
about any solution is going to have its drawbacks.

But you're right--most compilers don't optimize this well right now.

Things that are the fault of the language have to wait to a new
language spec to fix; things that are the fault of an implementation
are the kind of thing you can send a bug report about sooner than that.
Of course, if the entire user community declines to use keywords because
they're slow, then they'll never get fixed and never get used.
Too bad.  I think they're one of the better language features.

And clever use of compiler macros can help you fix up some of the
speed problems even without vendor cooperation, btw.  I think things like 
CLIM (which publish keyword interfaces they want to be reliably fast)
do this.
From: Kelly Murray
Subject: Re: argument passing: defaults
Date: 
Message-ID: <60v8lr$hhf$1@vapor.franz.com>
> Things that are the fault of the language have to wait to a new
> language spec to fix; things that are the fault of an implementation
> are the kind of thing you can send a bug report about sooner than that.
> Of course, if the entire user community declines to use keywords because
> they're slow, then they'll never get fixed and never get used.
> Too bad.  I think they're one of the better language features.

Absolutely, keyword args one of the great features of CL.
The CL standard went way overboard, but the basic idea is super.

They provide a huge win for webserver scripting, since
a URL can map to a CL function call pretty much directly,
which is how my Charlotte webserver works for doing server-side scripting.

(function openfolder (&key folder getmail) ...)

is called via http://www.franz.com/openfolder?&folder=inbox&getmail=yes

and even optional and rest args are very useful

(function showuser (&optional name &rest attributes)

http://www.franz.com/showuser 
or
http://www.franz.com/showuser?fred 
or
http://www.franz.com/showuser?fred+name+phone+address

etc.

Now that is what I'd call "Elegant" for a language, 
at least for the domain of web server scripting.

-Kelly Murray   ···@franz.com