Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ginosko!uunet!mcsun!ukc!edcastle!aiai!jeff From: jeff@aiai.uucp (Jeff Dalton) Newsgroups: comp.lang.lisp Subject: Re: optional and key arguments Message-ID: <816@skye.ed.ac.uk> Date: 28 Aug 89 14:32:33 GMT References: <64922@linus.UUCP> Sender: news@aiai.ed.ac.uk Reply-To: jeff@aiai.uucp (Jeff Dalton) Distribution: comp.lang.lisp Organization: AIAI, University of Edinburgh, Scotland Lines: 33 In article <64922@linus.UUCP> bds@mbunix (Smith) writes: >(defun test (a b &optional (c 0) &key (d 1)) > (if (= d 1) > (+ a b c d) > (+ a b c))) >(test 5 4 :d 0) results in an error. >Since optional arguments are evaluated first, c is bound to :d, and 0 >isn't a key argument. Is this the Common Lisp standard? If so, does >it make sense? In our case, we had 3 optional arguments, and we >wanted to use the default values, but to set the key argument to >something else. It seems a violation of the notion of optional >arguments to have to specify them. This behavior is correct Common Lisp. To specify any arguments that occur after the optional ones, you have to specify the optional arguments. The reason it may look strange in this case is that you seem to be supposing that use of a keyword in a function call should automatically indicate a keyword parameter. However, keywords are just a kind of symbol and are used for a number of different purposes. For example, in (LIST :A :B) => (:A :B), both :A and :B are used just as data objects, and neither indicates that a keyword parameter should follow. If you never want to use keywords except to indicate keyword parameters, you may well think that Common Lisp has made a mistake. But many programmers do use keywords for other purposes. For example, in some object systems, keywords are used a method names, as in (send aWindow :redisplay) -- Jeff