I am trying to write a Lisp function that can take optional and keyword arguments. The function begins
(defun max-min (v &optional max min &keyword (start 0) (end nil))
When I try to call the function using the keyword arguments but not the optional ones, I get an error. What I’m trying to do is
(max-min #(1 2 3 4) :start 1 :end 2)
I’m getting the error Error: :START' is not of the expected type REAL'
I assume that this is because it is trying to bind :start to max. How can I get this to work? Thanks.
You need to call that function with the required parameter, the optional parameters and then the keyword parameters. How should it work otherwise? Your call lacks the optional parameters. If you want to specify keyword parameters in the call, the optional are no longer optional.
The basic style rule:
Don’t mix optional with keyword parameters in a function. Common Lisp for example uses it in some place and it is a source of bugs.
CL:READ-FROM-STRINGis such an example.http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_fro.htm
This works:
This may work also:
But the user forgot to specify the EOF-ERROR-P and EOF-VALUE. The Lisp compiler may not complain and the user will wonder why it won’t start at 2.