In Python, you can pass a list or tuple to a function and have the function unpack the argument. How can I do that in Clojure? Here is some example Python code:
def f (a, b, c, *d):
print "a: ", a
print "b: ", b
print "c: ", c
print "d: ", d
f (1, 2, 3, 4, 5, 6)
print
v = (4, 5, 6)
f(1, 2, 3, *v)
result:
a: 1
b: 2
c: 3
d: (4, 5, 6)
a: 1
b: 2
c: 3
d: (4, 5, 6)
in my clojure code:
(defn f [a b c & d]
(println "a: " a)
(println "b: " b)
(println "c: " c)
(println "d: " d))
(f 1 2 3 4 5 6)
(println)
(def v [4 5 6])
(f 1 2 3 v)
result:
a: 1
b: 2
c: 3
d: (4 5 6)
a: 1
b: 2
c: 3
d: ([4 5 6])
the d have one element only, how can I let result as python code?
Clojure does not unpack arguments from a vector with a language feature, like Python does.
The closest thing to unpacking is function apply.
In this particular case:
Prints: