我想定义一个在juxt中使用的函数列表,但是我在实现它时遇到了麻烦.
下面是我想要的一个例子:
(defn sin [n] (Math/sin n))
(defn cos [n] (Math/cos n))
((juxt sin cos) 4)
>> [-0.7568024953079282 -0.6536436208636119]
Run Code Online (Sandbox Code Playgroud)
现在,而不是说((juxt sin cos) 4)我宁愿说((juxt trig) 4)在哪里
(def trig [sin cos]).我尝试((apply juxt trig) 4)了一些其他的东西,但似乎没有什么可以坚持下去.谢谢!
apply 似乎工作正常:
user=> ((juxt sin cos) 4)
[-0.7568024953079282 -0.6536436208636119]
user=> ((apply juxt trig) 4)
[-0.7568024953079282 -0.6536436208636119]
Run Code Online (Sandbox Code Playgroud)
我认为你有一个正确的解决方案.对我来说它有效:
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]
Run Code Online (Sandbox Code Playgroud)