Is there a function?

Discussion of Common Lisp
Post Reply
ls1evan
Posts: 2
Joined: Thu Apr 14, 2011 12:40 am

Is there a function?

Post by ls1evan » Thu Apr 14, 2011 12:49 am

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

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Is there a function?

Post by ramarren » Thu Apr 14, 2011 2:15 am

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Is there a function?

Post by nuntius » Thu Apr 14, 2011 6:55 am


ls1evan
Posts: 2
Joined: Thu Apr 14, 2011 12:40 am

Re: Is there a function?

Post by ls1evan » Thu Apr 14, 2011 4:14 pm

thanks!!

Post Reply