Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
edited by

This original version of this post asked about the pipe symbol as well the dollar sign, but there is an answer concerning the pipe symbol here: https://ask.clojure.org/index.php/11627/the-pipe-char-considered-valid-symbol-constituent-character

However, I'm still wondering about the dollar sign, $, which is not explicitly listed as a legal character for symbol names:
In practice it can be used in symbols:
(def $ 42) $ ;==> 42 (defn a$b [a b] (or a b)) (a$b nil 'foo) ;==> foo
Putting aside the question of whether it's stylistically or pragmatically appropriate (e.g. because of worry about confusing others) to use $ in symbol names (e.g. because of worry about confusing others), is there a technical reason to avoid it?

For example, are there edge cases where using $ in a symbol would cause trouble? Or is it possible that in the future Clojure would use $ as special syntax?

(I have in fact used $ in symbol names in the past.)

1 Answer

+1 vote

$ is used in a lot of places (like Datomic) and I don't expect that to be problematic in the future.

I guess the one place it's potentially confusing is that it is used in symbols naming classes to separate outer and nested classes. Which I guess argues that it is pervasive in symbols, but has meaning in some contexts, but those contexts are probably disjoint from your needs.
Thanks very much.  This is all good to know and very helpful.   (Yes, that case won't interfere with my intended and past uses.)