3

I would like to define a list of functions to use within juxt, however I am having trouble implementing it.

Heres an example of what I want:

(defn sin [n] (Math/sin n))
(defn cos [n] (Math/cos n))
((juxt sin cos) 4)
>> [-0.7568024953079282 -0.6536436208636119]

Now instead of saying ((juxt sin cos) 4) I would prefer to say ((juxt trig) 4) where (def trig [sin cos]). I have attempted ((apply juxt trig) 4) and a few other things but nothing seems to stick. Thanks!

2 Answers 2

5

apply seems to work fine:

user=> ((juxt sin cos) 4)
[-0.7568024953079282 -0.6536436208636119]
user=> ((apply juxt trig) 4)
[-0.7568024953079282 -0.6536436208636119]
Sign up to request clarification or add additional context in comments.

Comments

5

I think you have a correct solution. For me it works:

Clojure 1.2.1
user=> (defn sin [n] (Math/sin n))
#'user/sin
user=> (defn cos [n] (Math/cos n))
#'user/cos
user=> (def trig [sin cos])
#'user/trig
user=> ((apply juxt trig) 4)
[-0.7568024953079282 -0.6536436208636119]

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.