java 识别fn键,如何获得一个调用Java方法的Fn?

I'm learning Clojure. I wrote this code to recursively walk a directory.

(tree-seq #(.isDirectory %1) #(.listFiles %1) (File. "/my-directory"))

Why can't I use .isDirectory as a first-class function in Clojure? Is there a better way to rewrite this code?

解决方案

Java methods aren't clojure functions because you can't call a method on its own; you have to call a method on an object, and it has to be an object of the type that the method expects. In other words, in java, a method cannot be fully separated from its defining class (at least not efficiently).

An alternative to #(.foo %) would be (memfn foo), which hardly anyone uses anymore after #(...) was introduced.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值