tags:

views:

117

answers:

4

I have a function that works like that:

(the-function [one] [two] [three])

and I need a function that calls the-function.

I tried with [& args] but it doesn't seem to pass the arguments correctly.

If it helps, the-function is like the create-table of MySQL found here

EDIT: my function that is not working is like this:

(defn my-function [& args]
   (the-function args))

And I want to be able to do:

(my-function [one] [two] [three])

and call the-function with these arguments

+2  A: 

I don't understand the question. Could you give more detail?

apply is the function-calling-function,, eg:

(defn add-three [x y z] (+ x y z))

(add-three 1 2 3)
(apply add-three '(1 2 3))

Does that help?

John Lawrence Aspden
A: 

I am not sure I understand your question.

Is destructturing what you need?

(defn the-function [[one two three]]
  (println (str one two three)))

(defn myfunction [& args]
   (the-function args))
missingfaktor
yes but the definition of my-function is like the-function
Jon Romero
+4  A: 

Okay, what you want is this:

(defn my-function [& args] (apply the-function args))

Apply applies a function to a set of arguments in a sequence as if they were individual arguments.

Rayne
+1, Are you a Legilimens? ;-)
missingfaktor
Psh, like I'd tell you. ;)
Rayne
A: 

what is the & in [& args] ? (i'm new to clojure but i'm curious)

i know this is supposed to be a vector : [args]

Belun
It's for a variable number of arguments
Jon Romero