Clojure Vars vs. Indices / Links in other languages

I am trying to understand the concept of clojure Var .

As far as I can tell, this is just a link / pointer to a value. The “root value" of Var can be thought of as the initial value that indicates Var to flow. Moreover, I believe that - behind the scenes - each Var has an address for the position in the memory that it points to (although languages ​​like Java, Javascript do not give you access to this particular location and, perhaps, do something behind the scenes that make this address unstable anyway).

Question: Is it right to think about it? How is it wrong to think of clojure Var as a reference / pointer to a value?

Given something like

(def v 7)

Is it appropriate to say things like "Var #" v indicates a value of 7 "?

+4
source share
1 answer

Yes, this is a wonderful concept. I would slightly adjust your final statement:    #'vexpanding to (var v), it makes no sense to say var (var v), instead I would just say var v. I would also say the derefsvalue 7 instead of the points to. Yes, they behave like pointers, but they have a special form deref(or @) to dereference them (and you cannot do arithmetic operations with a pointer).

, deref Clojure: - , , (inc 1), ! inc - , var inc, (inc ! inc derefs ), vars deref. (var inc), deref. , var, , inc, .

, , , inc , - var. . inc - , var, . var inc . , v derefs 7 . v - var, . (, , , var, var ).

+4

Source: https://habr.com/ru/post/1629708/


All Articles