Page 1 of 1

Is there a function?

Posted: Thu Apr 14, 2011 12:49 am
by ls1evan
hello all!
Is there a function that takes a list and returns multiple arguments, one for each element in the list?
this would be the opposite of LIST (which takes multiple args and makes them into a list)
for example:
(mysteryfunction '(1 2 3))
1 2 3

((extra information: i need this because i have a function that takes 6 args, the last three of which are in a list of three arguments. i realize that i could use car, cadr, then caddr but that would be much messier))

thanks! :D

Re: Is there a function?

Posted: Thu Apr 14, 2011 2:15 am
by ramarren
There is APPLY. It uses spreadable argument lists, which means that in addition to the function to call it takes a variable number of arguments the final of which must be a list. Also see functions chapter of Practical Common Lisp.

Code: Select all

CL-USER> (defun example-6 (a b c d e f) (+ a b c d e f))
EXAMPLE-6
CL-USER> (apply #'example-6 1 2 3 (list 4 5 6))
21

Re: Is there a function?

Posted: Thu Apr 14, 2011 6:55 am
by nuntius

Re: Is there a function?

Posted: Thu Apr 14, 2011 4:14 pm
by ls1evan
thanks!!