Jump to content

&optional / &key


Recommended Posts

little lisp-problem/question with &optionel / &key... 

here are two test-programs to explore keyword and optional paramters

 

 

this test-program works

 

(defun test1 (liste  add  &key (add-on/off))
  (loop for i in liste 
    when (equal add-on/off 'on)
    collect (+ i add)
    else collect i))
 
(test1 '(1 2 3 4 5) 100 :add-on/off 'on)
 
 
this version with &optional don't work... why? 
 
(defun test2 (liste  add &optional (x 10) &key (add-on/off))
  (loop for i in liste 
    when (equal add-on/off 'on)
    collect (+ i add x)
    else collect i))
 
(test2 '(1 2 3 4 5) 100 :add-on/off 'on)
 
> Error: While compiling test2 :
>        Bad lambda list : (liste add &key add-on/off &optional (x 10)), in process Listener-1(7).
 
 
 
thanx for help
andré
 
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy