How is the `*var-name*` naming-convention used in clojure?

前端 未结 3 508
死守一世寂寞
死守一世寂寞 2020-12-29 03:59

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

This appears to be a lisp co

3条回答
  •  无人及你
    2020-12-29 04:28

    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).

    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.

    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.

提交回复
热议问题