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
apply
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With