如何在clojure中使用`* var-name *`命名约定? [英] How is the `*var-name*` naming-convention used in clojure?

查看:134
本文介绍了如何在clojure中使用`* var-name *`命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个非lisper来clojure我应该如何最好地理解命名约定,vars得到一个名称 * var-name *

As a non-lisper coming to clojure how should I best understand the naming convention where vars get a name like *var-name*?

这似乎是一个表示全局变量的Lisp约定。但在clojure这样的vars出现在命名空间,只要我能告诉。

This appears to be a lisp convention indicating a global variable. But in clojure such vars appear in namespaces as far as I can tell.

我真的很感激一个简单的解释,当一个作者在他们的代码中使用这样的var,我应该期望,理想情况下,如何和为什么这样var在clojure库中使用和更改。

I would really appreciate a brief explanation of what I should expect when an author has used such vars in their code, ideally with a example of how and why such a var would be used and changed in a clojure library.

推荐答案

这是一个在其他Lisps中使用的约定, 特殊变量 词汇变量。特殊或动态变量将它的绑定存储在动态环境中,这意味着它的当前值对于代码中的任何一点都是可见的,这取决于它如何绑定更高(例如 let defn ),而不是依赖于最本地的词法绑定形式)。

It's a convention used in other Lisps, such as Common Lisp, to distinguish between special variables, as distinct from lexical variables. A special or dynamic variable has its binding stored in a dynamic environment, meaning that its current value as visible to any point in the code depends upon how it may have been bound higher up the call stack, as opposed to being dependent only on the most local lexical binding form (such as let or defn).

请注意,在他的书 Let Over Lambda ,Doug Hoyte反对用于命名特殊变量的耳罩asterix约定。他使用一个不寻常的宏风格,引用自由变量,他不喜欢提交或区分这些符号是否最终引用词汇或动态变量。

Note that in his book Let Over Lambda, Doug Hoyte argues against the "earmuffs" asterix convention for naming special variables. He uses an unusual macro style that makes reference to free variables, and he prefers not to commit to or distinguish whether those symbols will eventually refer to lexical or dynamic variables.

具体针对Common Lisp,您可能喜欢 Ron Garret 的文章 The Idiot的特殊变量指南 。它大部分仍然适用于Clojure。

Though targeted specifically at Common Lisp, you might enjoy Ron Garret's essay The Idiot's Guide to Special Variables. Much of it can still apply to Clojure.

这篇关于如何在clojure中使用`* var-name *`命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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