Is there a form in any lisp that could "spread" a list in the parent sexp? Like:
(+ (spread '(1 2 3))) -> (+ 1 2 3)
There are two way to do it. Which is better depends on what you want in the end.
Generally, you can use ,@
inside `
(backquote). The form following ,@
is evaluated to produce a list, which is then spliced into the template:
* `(+ ,@'(1 2 3))
(+ 1 2 3)
* (eval `(+ ,@'(1 2 3)))
6
Or, if you just want to call a function with its arguments which are packed in a list, it will be more convenient to use the apply
function:
* (apply #'+ '(1 2 3))
6
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