宏 - >与匿名函数 [英] macro -> with anonymous functions

查看:101
本文介绍了宏 - >与匿名函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解宏 - > in clojure是应用提供给参数的所有函数。但是,它似乎不工作与匿名函数(在clojure 1.3.0)。例如:

I understand the macro -> in clojure is applying all the functions provided to the argument given. However, it doesn't seem to work with anonymous functions (on clojure 1.3.0). 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆