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

5
  • I'm not sure what you're asking. You want your function to call the-function how exactly? Commented Aug 23, 2010 at 11:10
  • @Jon: Your edit is even more confusing. Commented Aug 23, 2010 at 11:22
  • I am pretty sure it's a stupid question and that makes it even more difficult to express it correctly. Commented Aug 23, 2010 at 11:26
  • @Jon: From your profile Python seems to be your primary language. Try to express what you want to do, with the help of Python. We'll try to tell you how to do it in Clojure. Commented Aug 23, 2010 at 11:33
  • Thanks @MF! Seems that the answer was just an apply :) Commented Aug 23, 2010 at 11:36

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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?

Comments

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.