<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 10, 2015 at 5:46 PM, Thomas Gebert <span dir="ltr"><<a href="mailto:thomas@gebert.sexy" target="_blank">thomas@gebert.sexy</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I know this is probably kind of a newbie question, but I figured this would be the place to ask it: if atoms aren't garbage collected, why should I use them?</blockquote></div><br>1) Pierre notes: runtime characteristics are different. This in itself is an important reason.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Having a way to introduce static names in code with O(1) comparison helps in defining structure. This structure can then be used in pattern matches to quickly discriminate between cases. If you define</div><div class="gmail_extra"><br></div><div class="gmail_extra"> {user, "tombert", "easts pizza"},</div><div class="gmail_extra"><br></div><div class="gmail_extra">you are using a common pattern where the first tuple-argument encodes what the remainder of the tuple contains. It has some reminiscence of algebraic datatypes in languages which support those, and is somewhat Erlang's ways of getting access to these.</div><div class="gmail_extra"><br></div><div class="gmail_extra">From a programmers perspective:</div><div class="gmail_extra"><br></div><div class="gmail_extra">atoms: used for statically declared words by the programmer and are avoided for dynamic generation and input controlled by an "enemy".</div><div class="gmail_extra">binaries: used in places where space saving is paramount, and for data which contain truly binary information.</div><div class="gmail_extra">strings: textual strings and the rest of the systems string-like objects are represented as lists of code-points.</div><div class="gmail_extra"><br clear="all"><div>Apart from this, there are cases where it is nice to signify "namespace difference" by using atoms. e.g., in the term</div><div> </div><div> {user, "tombert", "eats pizza"},</div><div><br></div><div>A reader immediately understands that 'user' is something the programmer has supplied, whereas "tombert" and "eats pizza" are probably sattelite data entered by a user at some point. Had we writte, e.g., "user", then you somewhat tell the reader that "user" is a field which might get changed to "anything", whereas the atom 'user' signifies that there might be other kinds of terms used in this place, but there is only a finite amount of those.</div><div><br></div><div>Of course, YMMV, and some people have other views as to how and where to use the different classes. There are also people who thinks we should GC atoms such that we can reuse them freely. The major reason this has not happened yet, is that one has to come up with a good scheme that doesn't slow the interpreter down too much, or breaks the soft-realtime properties of the system.</div><div><br></div>-- <br><div class="gmail_signature">J.</div>
</div></div>