From ... From: Erik Naggum Subject: Re: Q: optional arguments default values: evaluated when? Date: 1999/11/08 Message-ID: <3151027418201097@naggum.no>#1/1 X-Deja-AN: 545787524 References: mail-copies-to: never X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 942038620 5155 193.71.66.49 (8 Nov 1999 05:23:40 GMT) Organization: Naggum Software; +47 8800 8879 or +1 510 435 8604; fax: +47 2210 9077; http://www.naggum.no NNTP-Posting-Date: 8 Nov 1999 05:23:40 GMT Newsgroups: comp.lang.lisp * Matthew Economou your subject question is precise enough for an answer, so the complex and possibly confusing example has been elided. the default value of an optional argument is evaluated in the lexical scope of any previously specified arguments, and any free variables are referenced as per the usual rules: ((lambda (foo &optional (bar foo) (zot bar)) (list foo bar zot)) t) ==> (t t t) or, quoting from the standard: 3.4.1.2 Specifiers for optional parameters If &optional is present, the optional parameter specifiers are those following &optional up to the next lambda list keyword or the end of the list. If optional parameters are specified, then each one is processed as follows. If any unprocessed arguments remain, then the parameter variable var is bound to the next remaining argument, just as for a required parameter. If no arguments remain, however, then init-form is evaluated, and the parameter variable is bound to the resulting value (or to nil if no init-form appears in the parameter specifier). If another variable name supplied-p-parameter appears in the specifier, it is bound to true if an argument had been available, and to false if no argument remained (and therefore init-form had to be evaluated). Supplied-p-parameter is bound not to an argument but to a value indicating whether or not an argument had been supplied for the corresponding var. #:Erik -- Attention Microsoft Shoppers! MS Monopoly Money 6.0 are now worthless.