线程宏 ->带有匿名函数 [英] threading macro -> with anonymous functions
本文介绍了线程宏 ->带有匿名函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我理解 Clojure 中的 `-> 标题宏将所有提供的函数应用于给定的参数.但是,它似乎不适用于匿名函数.例如:
I understand the `-> theading macro in Clojure applies all the provided functions provided to a given argument. However, it doesn't seem to work with anonymous functions. For example:
user> (-> 4 inc inc dec)
5
但是:
user> (-> 4 #(+ % 1) #(- % 1) #(+ % 1))
返回错误:
clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector
[Thrown class java.lang.ClassCastException]
如果有人知道解决方法会很有帮助.谢谢!
If someone knows a way around it would be helpful. Thanks!
推荐答案
您可以在 Clojure 宏中使用匿名函数.您遇到了问题,因为您缺少一些括号.:) 您的示例在下面进行了编辑.
You can have anonymous functions in Clojure macros. You are having problems, because you are missing some parentheses. :) Your example is edited below.
(-> 4 (#(+ % 1)) (#(- % 1)) (#(+ % 1)))
这篇关于线程宏 ->带有匿名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文