문제

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?

도움이 되었습니까?

해결책

다른 팁

Use the apply function:

(apply #'function arguments)

Example:

CL-USER> (apply #'(lambda (a b c) (+ a b c)) '(1 2 3))
6   
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top