Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!cs.utexas.edu!milano!perseus!rcp From: rcp@perseus.SW.MCC.COM (Rob Pettengill) Newsgroups: comp.lang.lisp Subject: Re: Are optional arguments required? Keywords: CommonLISP, optional and keyword arguments. Message-ID: <1016@perseus.SW.MCC.COM> Date: 11 Aug 88 05:31:54 GMT References: <15115@shemp.CS.UCLA.EDU> Reply-To: rcp@perseus.sw.mcc.com.UUCP (Rob Pettengill) Distribution: na Organization: MCC Software Technology Program Lines: 37 In article <15115@shemp.CS.UCLA.EDU> leo@CS.UCLA.EDU (Leonid V. Belyaev) writes: ;There seems to be at least one case where &optional arguments are actually ;required. Here is a simple function I was trying to define: ; ; (defun test-args (req1 &optional (opt1 'opt1) ; &key (key1 'key1) ; (key2 'key2)) ; (format t "Arguments:~%~%") ; (format t "REQ1: ~A~%" req1) ; (format t "OPT1: ~A~%" opt1) ; (format t "KEY1: ~A~%" key1) ; (format t "KEY2: ~A~%" key2) ; (format t "~%") ; (values)) ; ;Seems fine so far. Now, when you call TEST-ARGS with arguments ; ; 1 2 :key1 3 ; ;everything is fine. However, arguments ; ; 1 :key1 2 ; ;result in an error. The optional argument must be supplied before the ; ... When an optional argument beyond the first one is to be supplied then all of the preceeding optional arguments must be supplied. In order to avoid ambiguity in the interpretation of the values passed, all optional arguments must be specified before keyword arguments when both are passed. Zetalisp used to distinquish between required and optional keyword arguments - Common Lisp has only optional keyword arguments. Read the description of lambda list processing in Section 5.2.2 (page 61). All optional parameters are bound before any keyword parameters are bound. This is exactly the behavior you describe. ;rob