Jump to content

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))

 

Link to comment
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

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