steve@et.UUCP (06/17/87)
Does anyone have a good definition of exactly what the &optional keyword does in the function parameter definitions. I have the general idea and I wish to use it for some of my functions, but I don't know some things like: 1. What values do the optional parameters acquire if they are not passed by the calling routine? 2. Is there some way to specify a default value if they are not passed by the calling routine? * Most Important * 3. Is there a limit to the number of optional parameters and can a function have nothing but optional parameters. I can not wait until the programmer's manual becomes available. It will aid life in extension writing immeasurably. Thanks in advance. +--------------------------------------------------------------------------+ | 'et' (edmonton telephones) | Steve Hole (steve@et.UUCP) | | Etcom International | rm 906, 10044 - 108 st. | | OUR REPUTATION IS ALWAYS ON THE LINE | Edmonton Alta, CAN. T5J 2R4 | | (standard disclaimer) | (403) 441-7673 | +--------------------------------------------------------------------------+
wolfgang@haddock.UUCP (Wolfgang Rupprecht) (06/19/87)
> 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
drw@cullvax.UUCP (Dale Worley) (06/19/87)
steve@et.UUCP (Steve Hole) writes: > Does anyone have a good definition of exactly what the &optional > keyword does in the function parameter definitions. I have the > general idea and I wish to use it for some of my functions, but I > don't know some things like: If the parameter isn't given, it value is nil. Presumably, all perameters can be optional. There may be a limit on the number of parameters, but I'll bet it's large. Dale -- Dale Worley Cullinet Software ARPA: cullvax!drw@eddie.mit.edu UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw If you light a match, how much mass does it convert into energy?