Jump to content
Sign in to follow this  
AM

a simple lisp question

Recommended Posts

is it possible to do such a (nonsense-function) with mapcar (then with loop)?

-> how should i handle the &key (y 1) with mapcar? possible? a function without &key is clear but with &key ....???

 

thanx for a note

 

(defun testfu (value &key (y 1))
  (* (random 10) value y))

(loop 
  for i in '(1 2 3 4 5)
  for j in '(1 2 3 4 5)
  collect (testfu i :y j))

 

Share this post


Link to post
Share on other sites

(defun testfu (value &optional (y 1))
  (* (random 10) value y))

 

(mapcar #'testfu
        '(1 2 3 4 5)
        '(1 2 3 4 5))

 

I am not aware how you could handle a keyword directly by map car, but you can always turn the keyword argument into a plain argument in an intermediate function.

 

(defun testfu (value &key (y 1))
  (* (random 10) value y))

 

(mapcar #'(lambda (x y) (testfu x :y y))
        '(1 2 3 4 5)
        '(1 2 3 4 5))

 

Best,

Torsten

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×