Why does Clojure gensym increase by three with every call?

Quite unexpectedly for lisps, but looking at the sequential integer generation code, I noticed that repeated calls (gensym)increased the number indicated after the prefix by 3. I wonder why this is so.

user=> (gensym)
G__662
user=> (gensym)
G__665
user=> (gensym)
G__668
user=> (gensym)
G__671
user=> (gensym)
G__674
user=> (gensym)
G__677

I have seen and understood sharing atomand inc, but I'm new to the function gensym.

+4
source share
2 answers

There are a few correct answers here. One of them: it is not!

user> (take 5 (repeatedly gensym))
(G__2173 G__2174 G__2175 G__2176 G__2177)

: gensym , , , ( ). , , gensym .

: ? , repl, gensym. -, (gensym) , , .

+12

!

=> (str (gensym) (gensym))
"G__4027G__4028"

gensym, , clojure.lang.RT/nextID.

(defn gensym
  ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID))))))))

id LispReader. , (gensym), , , .

- , , gensym , 3.

https://github.com/clojure/clojure/search?q=nextid

+3

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


All Articles