Question

In Python, assuming the following function is defined:

def function(a, b, c):
    ... do stuff with a, b, c ...

I am able to use the function using Python's sequence unpacking:

arguments = (1, 2, 3)
function(*arguments)

Does similar functionality exist in Common Lisp? So that if I have a function:

(defun function (a b c)
    ... do stuff with a, b, c ...

And if I have a list of 3 elements, I could easily use those 3 elements as parameters to the function?

The way I currently implement it is the following:

(destructuring-bind (a b c) (1 2 3)
    (function a b c))

Is there a better way?

Was it helpful?

Solution

OTHER TIPS

Use the apply function:

(apply #'function arguments)

Example:

CL-USER> (apply #'(lambda (a b c) (+ a b c)) '(1 2 3))
6   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top