# On Symbols

**URL:** <https://rubytalk.org/t/on-symbols/23687>\
**Category:** ruby-talk\
**Created:** [30 December 2005 13:39 UTC](https://rubytalk.org/t/on-symbols/23687 "2005-12-30T13:39:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devin\_Mullins](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Devin\_Mullins](https://rubytalk.org/u/Devin_Mullins)\
**Post date:** [30 December 2005 13:39 UTC](https://rubytalk.org/t/on-symbols/23687/1 "2005-12-30T13:39:34Z")

</div>

Hey, all you lurkers:

Have any of the explanations in the thread (What is the difference between :foo and "foo" ?) helped you understand symbols? A combination of them? Or a combination of a couple of explanations, and an irb session? Which ones? Why? If you don't want to get involved in (what seems to be turning into) a flamewar, email me personally (hint: don't click "Reply" :P), and I'll compile the results anonymously.

I think we all agree that everybody learns differently, and so I think we're in dire need of feedback from somebody other than Chad (no offense).

Devin

---

<div class="post-metadata">

**Author:** ![Ryan\_Leavengood](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ryan\_Leavengood](https://rubytalk.org/u/Ryan_Leavengood)\
**Post date:** [30 December 2005 16:25 UTC](https://rubytalk.org/t/on-symbols/23687/2 "2005-12-30T16:25:29Z")

</div>

I don't know, they have always made sense to me, which is why I didn't  
post in that other thread. I think people are just overthinking  
things.

Zen and the Art of Ruby Programming: Symbols just are.

Ryan

> **···**
>
> On 12/30/05, Devin Mullins \<twifkak@comcast.net\> wrote:
> 
> > Hey, all you lurkers:
> > 
> > Have any of the explanations in the thread (What is the difference  
> > between :foo and "foo" ?) helped you understand symbols? A combination  
> > of them? Or a combination of a couple of explanations, and an irb  
> > session? Which ones? Why? If you don't want to get involved in (what  
> > seems to be turning into) a flamewar, email me personally (hint: don't  
> > click "Reply" :P), and I'll compile the results anonymously.
> > 
> > I think we all agree that everybody learns differently, and so I think  
> > we're in dire need of feedback from somebody other than Chad (no offense).
> > 
> > Devin

---

<div class="post-metadata">

**Author:** ![Mark\_Somerville](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@Mark\_Somerville](https://rubytalk.org/u/Mark_Somerville)\
**Post date:** [30 December 2005 16:52 UTC](https://rubytalk.org/t/on-symbols/23687/3 "2005-12-30T16:52:38Z")

</div>

> Hey, all you lurkers:

Hello.

> Have any of the explanations in the thread (What is the difference  
> between :foo and "foo" ?) helped you understand symbols? A combination  
> of them? Or a combination of a couple of explanations, and an irb  
> session? Which ones? Why? If you don't want to get involved in (what  
> seems to be turning into) a flamewar, email me personally (hint: don't  
> click "Reply" :P), and I'll compile the results anonymously.

Yes, the thread has definitely helped my understanding (but I wouldn't like to  
offer up my own explanation of how they work 😉 ). It's hard to pinpoint any  
one thing that made it click, but I think the host/port example on the second  
half of this page seemed to make the most difference to me:

[http://microjet.ath.cx/WebWiki/2005.12.27\_UsingSymbolsForTheWrongReason.html](http://microjet.ath.cx/WebWiki/2005.12.27_UsingSymbolsForTheWrongReason.html)

I found the examples of when to use symbols the most useful. In fact, I'd say  
they're essential, at least for me.

Thanks everyone.

Mark

> **···**
>
> On Friday 30 December 2005 13:39, Devin Mullins wrote:
> 
> > I think we all agree that everybody learns differently, and so I think  
> > we're in dire need of feedback from somebody other than Chad (no offense).
> > 
> > Devin

---

<div class="post-metadata">

**Author:** ![Dan\_Shafer](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@Dan\_Shafer](https://rubytalk.org/u/Dan_Shafer)\
**Post date:** [30 December 2005 19:18 UTC](https://rubytalk.org/t/on-symbols/23687/4 "2005-12-30T19:18:51Z")

</div>

What a long, sometimes interesting, sometimes confusing thread that has been (and apparently continues to be)!

For me, symbols weren't very mysterious. I'm a Ruby Nuby but I've been programming in languages that use symbols (e.g., Smalltalk) for a long time. I thought the most cogent response was the one that said all the discussion about what symbols \*really\* are under the covers were implementation details. I got it.

> **···**
>
> On Dec 30, 2005, at 5:39 AM, Devin Mullins wrote:
> 
> > Hey, all you lurkers:
> > 
> > Have any of the explanations in the thread (What is the difference between :foo and "foo" ?) helped you understand symbols? A combination of them? Or a combination of a couple of explanations, and an irb session? Which ones? Why? If you don't want to get involved in (what seems to be turning into) a flamewar, email me personally (hint: don't click "Reply" :P), and I'll compile the results anonymously.
> > 
> > I think we all agree that everybody learns differently, and so I think we're in dire need of feedback from somebody other than Chad (no offense).
> > 
> > Devin
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-  
> Dan Shafer  
> Technology Visionary - Technology Assessment - Documentation  
> "Looking at technology from every angle"
> 
> > **[Eclecticity.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=eclecticity.com)**
> >
> > Shop a wide selection of domains at HugeDomains.com. Find the right domain name today.

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [30 December 2005 23:36 UTC](https://rubytalk.org/t/on-symbols/23687/5 "2005-12-30T23:36:42Z")

</div>

None taken.

> **···**
>
> On Fri, Dec 30, 2005 at 10:39:34PM +0900, Devin Mullins wrote:
> 
> > I think we all agree that everybody learns differently, and so I think  
> > we're in dire need of feedback from somebody other than Chad (no offense).
> 
> --  
> Chad Perrin [CCD CopyWrite | [http://ccd.apotheon.org](http://ccd.apotheon.org) ]
> 
> "Real ugliness is not harsh-looking syntax, but having to  
> build programs out of the wrong concepts." - Paul Graham

---

<div class="post-metadata">

**Author:** ![Dave\_Howell2](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dave\_Howell2](https://rubytalk.org/u/Dave_Howell2)\
**Post date:** [4 January 2006 22:06 UTC](https://rubytalk.org/t/on-symbols/23687/6 "2006-01-04T22:06:00Z")

</div>

I've just started trying to find these discussions and read them because I haven't been at all clear on the difference, so I'll get back to you on what does work.

However, although I don't meant to pick on szpak specifically, he did provide a sterling example of what doesn't work, at least for me, and I have worked professionally as a writer of documentation....

&nbsp;&nbsp;"A symbol in Ruby is similar to a symbol in Lisp

I don't know Lisp. Or Java. Unless you know that your reader is already familiar with your reference, it's not helpful to use it.

&nbsp;&nbsp;&nbsp;&nbsp;in that the symbol is a name, or more precisely a named atom

"Atom" is undefined here. I know what an atom is. My desk is made of them. This is apparently some other kind of atom...

&nbsp;&nbsp;which can also respond to a request to expose itself as a number (to\_i) or a string (to\_s).

Neither names nor atoms respond to requests in my world. The use of "expose" is even more confusing.

&nbsp;&nbsp;In this case a Ruby symbol is similar to a Lisp keyword symbol

Is a Lisp keyword symbol different than a Lisp symbol?

&nbsp;&nbsp;(which is also prefixed by a colon (:), at least in some versions of Lisp).

Sometimes?

&nbsp;&nbsp;However, in Lisp a symbol has much greater functionality.  
&nbsp;&nbsp;For example, a Lisp symbol can also be bound to a value, a property list, or a function.

I definitely don't need to know what \*else\* a Lisp symbol can do. I would like to know what Ruby symbols \*are\* bound to, if not values, property lists, or functions. (I'm going to guess "string.")

&nbsp;&nbsp;In briefest, my understanding of symbol in Ruby is that it is an interned string used as a name  
&nbsp;&nbsp;("interned" meaning that it is entered into memory as a single, atomic entity, a monad -  
&nbsp;&nbsp;there is just one of it, with a single pointer to it).

Aha. I do know what a string is, and the definition of "interned" is supplied. However, the definition  
isn't very helpful. We're back to "atomic," with the implication that "normal" strings aren't atomic.  
Then there's "monad," but that's also undefined.

Again, this isn't intended to be a criticism of szpak specifically. He just provided a nice short example of what I see over and over again on this list. I don't know Lisp. I don't know Java. I don't know Smalltalk. I don't know PHP, or Python, or Perl, or C (plain, plussed, objective, or sharp). It's nice that there are lots of people on the list who do, and if you're trying to explain some part of Ruby to them, by all means, use common references. But don't assume we newbies know this stuff until we tell you.

Me, I know SQL, and AppleTalk, and REXX, and Modula-2, and Pascal, and real (not Real) BASIC, with line numbers. I decided I needed to learn a new language, something I could script and web and just generally do whatever I needed to do in. I picked Ruby.

Do I expect the myriad references to Python and Java to suddenly vanish from the list? Of course not. I'm just saying, if there's some big discussion about threading that uses Java as the counterexample, don't be surprised if I ask that same question a week later.

> **···**
>
> On Dec 30, 2005, at 5:39, Devin Mullins wrote:
> 
> > Hey, all you lurkers:
> > 
> > Have any of the explanations in the thread (What is the difference between :foo and "foo" ?) helped you understand symbols?

---

<div class="post-metadata">

**Author:** ![Amr\_Malik](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Amr\_Malik](https://rubytalk.org/u/Amr_Malik)\
**Post date:** [5 January 2006 05:26 UTC](https://rubytalk.org/t/on-symbols/23687/7 "2006-01-05T05:26:33Z")

</div>

The longish 'foo' vs :foo thread was helpful to me as a "nuby" in terms  
of understanding the ruby Symbols. Personally, I like to see the dirty  
details of what happens when a symbol is encountered in teh token  
stream:

For example, for me it would be instructional to hear from a Ruby expert  
as to what the interpreter does when it sees :foo or some such.

I don't think the discussions of lower level details are all bad. Most  
of us maybe new to Ruby, but most if not all, have quite a few years in  
computing, so there might still be instructional value in giving the  
details on what exactly happens when a ruby 'Symbol' is encountered in  
the token stream.

It might benefit those who wish to look a little deeper.

thanks to all the experts for taking the time to go over this for the  
benefit of us newcomers. (and then going the extra mile to ask whether  
it made sense.. now that's truly refreshing to see in an online  
community) 🙂

Cheers,

-A

Devin Mullins wrote:

> **···**
>
> > Hey, all you lurkers:
> > 
> > Have any of the explanations in the thread (What is the difference  
> > between :foo and "foo" ?) helped you understand symbols? A combination  
> > of them? Or a combination of a couple of explanations, and an irb  
> > session? Which ones? Why? If you don't want to get involved in (what  
> > seems to be turning into) a flamewar, email me personally (hint: don't  
> > click "Reply" :P), and I'll compile the results anonymously.
> > 
> > I think we all agree that everybody learns differently, and so I think  
> > we're in dire need of feedback from somebody other than Chad (no  
> > offense).
> > 
> > Devin
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![J\_Ryan\_Sobol](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@J\_Ryan\_Sobol](https://rubytalk.org/u/J_Ryan_Sobol)\
**Post date:** [30 December 2005 16:36 UTC](https://rubytalk.org/t/on-symbols/23687/8 "2005-12-30T16:36:29Z")

</div>

/agreed

~ ryan ~

> **···**
>
> On Dec 30, 2005, at 11:25 AM, Ryan Leavengood wrote:
> 
> > Zen and the Art of Ruby Programming: Symbols just are.

---

<div class="post-metadata">

**Author:** ![Christian\_Neukirche1](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Christian\_Neukirche1](https://rubytalk.org/u/Christian_Neukirche1)\
**Post date:** [30 December 2005 17:48 UTC](https://rubytalk.org/t/on-symbols/23687/9 "2005-12-30T17:48:47Z")

</div>

Ryan Leavengood \<leavengood@gmail.com\> writes:

> Zen and the Art of Ruby Programming: Symbols just are.

+1

> **···**
>
> > Ryan
> 
> --  
> Christian Neukirchen \<chneukirchen@gmail.com\> [http://chneukirchen.org](http://chneukirchen.org)

---

<div class="post-metadata">

**Author:** ![Ron\_M](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@Ron\_M](https://rubytalk.org/u/Ron_M)\
**Post date:** [30 December 2005 22:19 UTC](https://rubytalk.org/t/on-symbols/23687/10 "2005-12-30T22:19:49Z")

</div>

Ryan Leavengood wrote:

> I don't know, they have always made sense to me...

Ruby symbols surprised me a bit because unlike most  
Lisps, Ruby's symbols aren't garbage collected.

I still don't understand if that is an implementation  
detail or something fundamental about symbols in Ruby  
that makes them uncollectable. The answer to that  
question would say a lot about where it's a good  
idea to use symbols.

> Zen and the Art of Ruby Programming: Symbols just are.

In all languages with symbols, symbols just are.  
But in some languages they are, to varying degrees different.

> > Have any of the explanations in the thread (What is the difference  
> > between :foo and "foo" ?) helped you understand symbols?

The explanations that contrasted Ruby symbols with symbols  
in other languages helped me.

Symbols mostly similar but a little different to Ruby's  
are present in many languages (Lisp, Dylan).

Other languages have similar concepts with a different  
name (Interned strings in Java).

Other languages use the same term to describe something  
quite different (Lex/Yacc, APL's symbols, a linker's  
symbol table in C) - but that's mostly a different  
concept since the running program itself will rarely  
care about the symbols.

> **···**
>
> > On 12/30/05, Devin Mullins \<twifkak@comcast.net\> wrote:

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [30 December 2005 23:36 UTC](https://rubytalk.org/t/on-symbols/23687/11 "2005-12-30T23:36:17Z")

</div>

+= 1

> **···**
>
> On Sat, Dec 31, 2005 at 01:25:29AM +0900, Ryan Leavengood wrote:
> 
> > I don't know, they have always made sense to me, which is why I didn't  
> > post in that other thread. I think people are just overthinking  
> > things.
> > 
> > Zen and the Art of Ruby Programming: Symbols just are.
> 
> --  
> Chad Perrin [CCD CopyWrite | [http://ccd.apotheon.org](http://ccd.apotheon.org) ]
> 
> This sig for rent: a Signify v1.14 production from [http://www.debian.org/](http://www.debian.org/)

---

<div class="post-metadata">

**Author:** ![Dave\_Howell2](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dave\_Howell2](https://rubytalk.org/u/Dave_Howell2)\
**Post date:** [4 January 2006 22:18 UTC](https://rubytalk.org/t/on-symbols/23687/12 "2006-01-04T22:18:22Z")

</div>

Ack. I'm glad that helped somebody, but it was meaningless for me. It still had nothing about what a symbol \*is\*. Until I find out what they actually are, I can use them only by parrotting. "When I type attr\_reader, I have to do that colon-name thing, which then turns into an @name thing later for no visibly logical reason. But that's what you do, so I do it. La la la."

However, the link on that page seems to be much more useful to \*me\*.

[http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red](http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red)

[thinking]

Nope, still don't know what they are.

For pity's sake, though, do NOT respond to my message by trying to explain them. I haven't finished reading all the messages yet, but apparently there are a couple million, so no point in adding new ones just yet!

> **···**
>
> On Dec 30, 2005, at 8:52, Mark Somerville wrote:
> 
> > I think the host/port example on the second  
> > half of this page seemed to make the most difference to me:
> > 
> > [http://microjet.ath.cx/WebWiki/2005.12.27\_UsingSymbolsForTheWrongReason.html](http://microjet.ath.cx/WebWiki/2005.12.27_UsingSymbolsForTheWrongReason.html)

---

<div class="post-metadata">

**Author:** ![Dave\_Howell2](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dave\_Howell2](https://rubytalk.org/u/Dave_Howell2)\
**Post date:** [4 January 2006 22:47 UTC](https://rubytalk.org/t/on-symbols/23687/13 "2006-01-04T22:47:28Z")

</div>

> > Hey, all you lurkers:
> > 
> > Have any of the explanations in the thread (What is the difference between :foo and "foo" ?) helped you understand symbols?

Gregory Brown's examples showing object IDs have provided some hints, although I now feel an awful lot like Alice:

&nbsp;&nbsp;'You are sad,' the Knight said in an anxious tone: 'let me sing you a song to comfort you.'  
&nbsp;&nbsp;'Is it very long?' Alice asked, for she had heard a good deal of poetry that day.  
&nbsp;&nbsp;'It's long,' said the Knight, 'but very, VERY beautiful. Everybody that hears me sing it--either it brings the TEARS into their eyes, or else--'  
&nbsp;&nbsp;'Or else what?' said Alice, for the Knight had made a sudden pause.  
&nbsp;&nbsp;'Or else it doesn't, you know. The name of the song is called "HADDOCKS' EYES."'  
&nbsp;&nbsp;'Oh, that's the name of the song, is it?' Alice said, trying to feel interested.  
&nbsp;&nbsp;'No, you don't understand,' the Knight said, looking a little vexed. 'That's what the name is CALLED. The name really IS "THE AGED AGED MAN."'  
&nbsp;&nbsp;'Then I ought to have said "That's what the SONG is called"?' Alice corrected herself.  
&nbsp;&nbsp;'No, you oughtn't: that's quite another thing! The SONG is called "WAYS AND MEANS": but that's only what it's CALLED, you know!'  
&nbsp;&nbsp;'Well, what IS the song, then?' said Alice, who was by this time completely bewildered.  
&nbsp;&nbsp;'I was coming to that,' the Knight said. So saying, he stopped his horse and let the reins fall on its neck: then, slowly beating time with one hand, and with a faint smile lighting up his gentle foolish face, as if he enjoyed the music of his song, he began.

I'm developing the very strong suspicion that no explanation of symbols will get far unless it's part of a broader context that includes variables and references.

dblack said:

> a = "string" # a contains a reference to that string

and Gregory provided examples that indicate something more complicated: the `a' above contains a reference to an object, created especially for that variable, that contains six characters. Doing it again with variable `b' gives you an identical twin.

> a = 1 # a contains the actual (immediate) value 1

Except the example would seem to contradict this statement. `a' `b' and `c' do not contain actual anythings. They contain references to the same object, that object which is the value "1".

Maybe. I guess it depends on what, exactly, the .object\_id method returns, or on what "actual" or "immediate" means. It would appear it means something much less immediate than I'd expect.

"Named number" is beginning to make sense, to the degree that it's now clear there's some kind of serious difference between strings and (some kinds of?) numbers in Ruby.

On the other hand, there's still some serious ambiguity, because Gregory's numbers and strings were put into variables, but the symbols weren't stored in variables. What I need to figure out is how does a symbol differ from a string literal, numeric literal, or variable, not how it differs from a string or number IN a variable.

Onward.....

Once again, a gentle reminder: please feel free to comment on the learning process I'm documenting if you like, but do NOT respond if you're going to try to explain more about symbols and whatnot. Thanks!

> **···**
>
> On Jan 4, 2006, at 14:06, Dave Howell wrote:
> 
> > On Dec 30, 2005, at 5:39, Devin Mullins wrote:

---

<div class="post-metadata">

**Author:** ![Ross\_Bamford2](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@Ross\_Bamford2](https://rubytalk.org/u/Ross_Bamford2)\
**Post date:** [4 January 2006 23:07 UTC](https://rubytalk.org/t/on-symbols/23687/14 "2006-01-04T23:07:58Z")

</div>

Maybe (maybe?) there aren't any really good references out there on what a Ruby symbol is. And maybe you don't know Lisp. Maybe I don't either. But at least we both have a much wider field to Google now...

> **···**
>
> On Wed, 04 Jan 2006 22:06:00 -0000, Dave Howell \<groups@grandfenwick.net\> wrote:
> 
> > However, although I don't meant to pick on szpak specifically, he did provide a sterling example of what doesn't work, at least for me, and I have worked professionally as a writer of documentation....
> > 
> > &nbsp;&nbsp;"A symbol in Ruby is similar to a symbol in Lisp
> > 
> > I don't know Lisp. Or Java. Unless you know that your reader is already familiar with your reference, it's not helpful to use it.
> 
> --  
> Ross Bamford - rosco@roscopeco.remove.co.uk

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [5 January 2006 02:21 UTC](https://rubytalk.org/t/on-symbols/23687/15 "2006-01-05T02:21:09Z")

</div>

To be fair, I think the only reason he discussed the comparison of Ruby  
symbols to Lisp symbols is this (I use "he" in the generic here):

I wasn't getting a clear picture of what a Ruby symbol actually was from  
most of the comments about it, until I saw some evidence that it bore an  
at least passing resemblance to a Lisp symbol. While I'm no leet lisp  
haxxor type, I do have a halfway decent notion of what a symbol is in  
Lisp, so I pursued that comparison as a means of helping \*me\* understand  
what a Ruby symbol was, and szpak was responding to that. In other  
words that was kinda directed at me, and it did help me a bit to  
understand Ruby symbols, so as a special case explanation it did exactly  
what it needed to.

That having been said, if you'd like to try approaching the problem of  
uderstanding a Ruby symbol by way of learning what a Lisp symbol is and  
differentiating it from a Ruby symbol, let me know. I'll see if I can  
accomodate you. As far as my understanding of the subject goes, that  
seems to be the shortest path from zero to grokking.

> **···**
>
> On Thu, Jan 05, 2006 at 07:06:00AM +0900, Dave Howell wrote:
> 
> > However, although I don't meant to pick on szpak specifically, he did  
> > provide a sterling example of what doesn't work, at least for me, and I  
> > have worked professionally as a writer of documentation....
> > 
> > &nbsp;&nbsp;"A symbol in Ruby is similar to a symbol in Lisp
> > 
> > I don't know Lisp. Or Java. Unless you know that your reader is already  
> > familiar with your reference, it's not helpful to use it.
> 
> --  
> Chad Perrin [CCD CopyWrite | [http://ccd.apotheon.org](http://ccd.apotheon.org) ]
> 
> print substr("Just another Perl hacker", 0, -2);

---

<div class="post-metadata">

**Author:** ![Evan\_Webb1](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Evan\_Webb1](https://rubytalk.org/u/Evan_Webb1)\
**Post date:** [5 January 2006 07:23 UTC](https://rubytalk.org/t/on-symbols/23687/16 "2006-01-05T07:23:00Z")

</div>

Here is a short breakdown of how symbols (and other immediates are  
implemented):

A variable holds a value. That value is a integer. The value of the  
integer determines what it means. For example:

If the integer is odd, then the remaining bits of the integer are a  
Fixnum value.

This means that if you do

a = 0

the interpreter stores in the local variable table the value  
0x00000001. If you had assigned 4 to a, then the value would be  
0x00000041. This allows for all Fixnums to not require additional  
memory to represent. The same goes for true, false, nil, and symbols.  
For the first 3, they are:

Name Backend Integer Value

> **···**
>
> =========================  
> false 0  
> true 2  
> nil 4  
> undef 6 (This isnt accessible from native ruby code, but is used  
> internally)
> 
> For symbols, the least significant byte is 0x0e and the upper 3 bytes  
> are a integer. The integer is uniquely assigned value for a string.  
> Think about it as the table index for a string. By using a symbol, you  
> basically allocate a string once and then refer to it by the index it  
> occupies in a special symbol table. For example, the first time the  
> symbol :evan is seen, a string containing "evan" is created and stored  
> in the symbol table at, say, index 9323. The variable that was assigned  
> :evan gets assigned  
> ((9223 \<\< 8 ) | 0x0e). The next time :evan is seen, "evan" is looked up  
> in the symbol table to obtain 9232 again.
> 
> So, to review:
> 
> a = :evan
> 
> a.to\_i # =\> 9232 (the index in the symbol table)  
> a.object\_id # =\> 2363406 (the index \<\< 8 | 0x0e)  
> a.to\_s # =\> the reference to the string object located at  
> index 9232 in the symbol table
> 
> The ruby runtime rules take the integer value and apply the rules to  
> determine what it means. If it's odd, it's a Fixnum immediate value. If  
> it's 0,2,4, or 6, it's a "core" immediate value. If it has the LSB is  
> 0x0e, it's a symbol. Otherwise, it's a pointer to a memory address that  
> holds the information about the object.
> 
> Thats the end of days leason! Hope it helps!
> 
> Evan Webb // [evan@fallingsnow.net](mailto:evan@fallingsnow.net)

---

<div class="post-metadata">

**Author:** ![Greg\_Brown1](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@Greg\_Brown1](https://rubytalk.org/u/Greg_Brown1)\
**Post date:** [30 December 2005 18:13 UTC](https://rubytalk.org/t/on-symbols/23687/17 "2005-12-30T18:13:14Z")

</div>

+1 more. People will understand them if they just use them.

> **···**
>
> On 12/30/05, Christian Neukirchen \<chneukirchen@gmail.com\> wrote:
> 
> > Ryan Leavengood \<leavengood@gmail.com\> writes:
> > 
> > \> Zen and the Art of Ruby Programming: Symbols just are.
> > 
> > +1

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler5](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/austin_ziegler5/32/1985_2.png) [@Austin\_Ziegler5](https://rubytalk.org/u/Austin_Ziegler5)\
**Post date:** [31 December 2005 00:39 UTC](https://rubytalk.org/t/on-symbols/23687/18 "2005-12-31T00:39:14Z")

</div>

Probably an implementation detail. That doesn't mean you can't ignore  
it, but it means that it's generally a good idea to use Symbols in a  
lot of places. Just don't pretend that they're immutable Strings.  
They're not. If you want that, freeze the String.

-austin

> **···**
>
> On 30/12/05, Ron M \<rm\_rails@cheapcomplexdevices.com\> wrote:
> 
> > Ruby symbols surprised me a bit because unlike most  
> > Lisps, Ruby's symbols aren't garbage collected.
> > 
> > I still don't understand if that is an implementation  
> > detail or something fundamental about symbols in Ruby  
> > that makes them uncollectable. The answer to that  
> > question would say a lot about where it's a good  
> > idea to use symbols.
> 
> --  
> Austin Ziegler \* halostatue@gmail.com  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\* Alternate: austin@halostatue.ca

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [4 January 2006 23:13 UTC](https://rubytalk.org/t/on-symbols/23687/19 "2006-01-04T23:13:13Z")

</div>

Hi --

> dblack said:
> 
> > a = "string" # a contains a reference to that string  
> > a = 1 # a contains the actual (immediate) value 1
> 
> Except the example would seem to contradict this statement. `a' `b' and `c' do not contain actual anythings. They contain references to the same object, that object which is the value "1".
> 
> Maybe. I guess it depends on what, exactly, the .object\_id method returns, or on what "actual" or "immediate" means. It would appear it means something much less immediate than I'd expect.

I've always conceptualized it as pretty much a value vs. pointer  
difference. I avoid the word "pointer" because (a) Matz never calls  
it that, and (b) it's not a matter of physical memory, but a Ruby-side  
notion of reference. Still, it's close to the same idea.

Fixnums, Symbols, true, false, and nil get assigned directly to  
variables. For other objects, variables get a reference to the  
object. References, like variables, are not themselves objects.  
They're part of a kind of language substratum on which the object  
system floats.

I think that's all there is to it. In fact, in a sense there's even  
less to it, since Ruby handles any necessary de-referencing for you,  
so you don't have to make any explicit distinction in your code.

> Once again, a gentle reminder: please feel free to comment on the learning process I'm documenting if you like, but do NOT respond if you're going to try to explain more about symbols and whatnot. Thanks!

I'm giving myself a directly-quoted-person exemption 🙂

David

> **···**
>
> On Thu, 5 Jan 2006, Dave Howell wrote:
> 
> --  
> David A. Black  
> dblack@wobblini.net
> 
> "Ruby for Rails", from Manning Publications, coming April 2006!
> 
> > **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
> >
> > NEWER EDITION AVAILABLE
> > 
> > The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> > 
> > 
> > Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)\
**Post date:** [5 January 2006 12:27 UTC](https://rubytalk.org/t/on-symbols/23687/20 "2006-01-05T12:27:59Z")

</div>

evanwebb@gmail.com wrote:

> Thats the end of days leason! Hope it helps!
> 
> Evan Webb // evan@fallingsnow.net

Nicely done, Evan! Very good explanation. Thanks!

[Next page](https://rubytalk.org/t/on-symbols/23687.md?page=2)
