Jump to content

Featured Replies

Posted

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é
 
 
  • Author

thanx, that's the way it works

a.

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy