by kazinator · 6y ago · 0 comments
According to this coding guideline, you cannot develop a .fasl format that is made of Lisp read syntax, or exploit Lisp for sophisticated, structured data formats in general.
((juxt type identity) (clojure.edn/read-string "x"))
[clojure.lang.Symbol x]
It seems that the reader returns symbols just fine.The documentation for EDN says that "nil, booleans, strings, characters, and symbols are equal to values of the same type with the same edn representation." The only way two symbol values can be equal is if they are actually same symbol, I would hope.
Why is this important? Specifically, why do symbols need to be interned?
In Clojure, "Two symbols are equal if they have the same namespace and symbol name." In general, "Clojure’s = is true when comparing immutable values that represent the same value, or when comparing mutable objects that are the identical object." [1]
Because symbols are used to refer to things, whether or not they are mutable can be blurry. You can make symbols as immutable as you want, but as soon as you make one of those symbols a key which refers to a mutable object, such as a global environment, then effectively, the symbol appears as a gateway to something mutable, and you can't necessarily tell whether the mutability is in the symbol itself or something beyond it.
For instance, let's consider global variables. The definition of a global variable has an effect which we can inspect if we have a boundp function:
(boundp 'x) -> nil
(defvar x)
(boundp 'x) -> t
That can be made to work by mutating the symbol (the global binding information can be right inside the symbol). Or it could be working by keeping the symbol immutable, but mutating some hash table of bindings.Either way, the symbol looks interned, because we have mentioned it several times, and those mentions seem to be connected. The (defvar x) has an effect on (boundp 'x) and so they are referring to an x which is somehow the same.
It could work with x actually be a kind of character string, which got separately allocated three times. As long as we can't show any property of the system indicated by x to be different based on which copy of x we are using to enquire (e.g. boundp reports true for one x and false for another), then x looks interned.
eq: http://www.lispworks.com/documentation/HyperSpec/Body/f_eq.h...
With that said, I always thought symbols would intern, but that's not the case. It is true with keywords, however.
(identical? (clojure.edn/read-string "x") 'x) => false
(= (clojure.edn/read-string "x") 'x) => true
(identical? (clojure.edn/read-string ":x") :x) => true
They are, at best, cargo culted symbols: character strings with a tag bit which says "read/print me without quotes, so I visually look like something out of Lisp".