Clojure宏总是泄漏? [英] Are Clojure macros always leaky?

查看:176
本文介绍了Clojure宏总是泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您阅读了宏 - >使用匿名函数,您会看到 - > 宏在匿名函数中不能很好地运行。要正确使用宏,您需要了解实现。在这个意义上,宏是leaky - 实现不完全被API隐藏。

If you read the question macro -> with anonymous functions you'll see that the -> macro doesn't play well with anonymous functions. To use the macro correctly you need to understand the implementation. In that sense, the macro is "leaky" - the implementation is not completely hidden by the API.

这是一个(足够复杂的)Clojure宏leaky?

Is it always that case that a (sufficiently complex) Clojure macro is leaky?

[为了比较:C预处理器出现类似的问题,当粗心处理宏参数时,可以看到奇怪的副作用。在这种情况下,可以通过将宏参数包含在括号中(在宏内部)来解决问题。这并不能解决使用具有可变状态的C宏的问题(即每次使用参数时都会改变状态),但也许我们可以忽略函数式语言的问题,或者使用 let 以避免多次评估。]

[For comparison: A similar issue occurs with the C pre-processor, where strange side effects can be seen when macro arguments are handled carelessly. In that case, issues can be solved by enclosing the macro arguments in parentheses (inside the macro). That does not solve the issue of using C macros with mutable state (ie where each use of the argument mutates state), but perhaps we can either ignore that issue for functional languages, or use let to avoid multiple evaluations.]

推荐答案

您不需要了解实现 - docstring很清楚到它如何工作。阅读器宏也有很好的文档 - #(...)将扩展到(fn [..] ...)。鉴于这些知识和提供的信息docstring它明确,线程匿名函数将无法工作。不需要了解实施。

You don't need to understand the implementation - the docstring is quite clear as to how it works. Reader macros are also well documented - #(...) will expand to (fn [..] ...). Given this knowledge and the information provided docstring it's clear that threading anonymous functions won't work. No need to understand the implementation at all.

这篇关于Clojure宏总是泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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