Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!clyde!ima!haddock!wolfgang From: wolfgang@haddock.UUCP (Wolfgang Rupprecht) Newsgroups: comp.emacs Subject: Re: &optional keywords in function parameters Message-ID: <585@haddock.UUCP> Date: Thu, 18-Jun-87 22:33:35 EDT Article-I.D.: haddock.585 Posted: Thu Jun 18 22:33:35 1987 Date-Received: Mon, 22-Jun-87 00:56:22 EDT References: <197@et.UUCP> Reply-To: wolfgang@haddock.ISC.COM.UUCP (Wolfgang Rupprecht) Distribution: na Organization: Home for Wayward Programmers Lines: 38 Keywords: &optional > 1. What values do the optional parameters acquire if they are not > passed by the calling routine? Lisp should be fun. Why not experiment a bit? Just to get thing rolling: (progn (defun foo (&optional bar) ; define foo "a silly test function" ; docstring bar) ; return bar (foo) ; execute foo ) ;<- put cursor before this semi, type ^X^E The answer will appear in the mini-buffer. It turns out that this is *always* the value that unpassed &optional variables take on. > 2. Is there some way to specify a default value if they are not > passed by the calling routine? how about: (progn (defun foo (&optional bar) "second version" (or bar "default-value")) ; return the string "default-value" (foo) ; if bar is unset ) ;<- put cursor before this semi, type ^X^E > 3. Is there a limit to the number of optional parameters and can a > function have nothing but optional parameters. You can certainly have only optionals, as in the above example. I'll have to hedge on the max number of params that can be passed. That answer is certainly 1) large 2) implementation dependent. Any good lisp text such as "Lisp" by Winston & Horn, Addison Wesley or "Common Lisp" by Steele, Digital Press will answer all of these questions. -- Wolfgang Rupprecht {decvax!cca|yale|ihnp4|cbosgd|bbncca|harvard}!ima!haddock!wolfgang