Demystifying Symbols

I think the keychain analogy has some possibilities.

Ruby make a new keychain tagged "sillyNum." There isn't a key on this yet. That's what "nil" is; a keychain without a key.

No. The new keychain has a single key on it to the mailbox containing the object known as nil.

sillyNum = population + 14 / "5".to_i

How about something a little simpler:

  a = b + 1

Ruby finds the mailbox that matches the key on the keychain labeled b.

There is a slot on the side of the object inside the mailbox.
Ruby makes a copy of the key on the :+ keychain and inserts it in the slot.
Ruby makes a copy of the key on the 1 keychain and inserts it in the slot.
Ruby then presses a button next to the slot. The button is labeled 'send'.
Ruby waits a bit and then a new key clanks as it falls into a bin labeled 'return value'.
Ruby attaches the new key to the keychain labeled a, discarding any key that was there before.

Gary Wright

···

On Jan 7, 2006, at 7:40 PM, Dave Howell wrote:

I'll be honest, as a rubynewbie I liked Jim's description of variables
better than any other description I've heard here so far,
and I'm going to go read his post on symbols and
see if that jives with me as well.

Jim's definition:
Variables are like dictionary definitions bound to an object.
VarA = VarB = ObjectZ

Explanation:
If you looked up the definition of VarA in our dictionary it would say 'ObjectZ'
and likewise if you looked up the definition for VarB in our
dictionary it would say 'ObjectZ'.

No, pointer, no container, no pigeon hole or shoebox.. just a strait forward
term bound to a definition.

This maps nicely to the real world where you can look up the word 'house cat'
in a dictionary and find that it maps to 'small domesticated
carnivorous mammal', the cat
doesn't 'point' to a carnivore in a pigeon hole, and it doesn't
'contain' a carnivore in a shoebox. 'House cat' is simply a term bound
to a definition in our dictionary.

In this dictionary more than one variable is permitted to be bound to
the same object:
small_dog = house_cat = 'small domesticated carnivorous mammal'

In a real dictionary terms are bound to descriptions, but in the ruby
dictionary
of variables we would say terms are bound to objects, this boils down
to exactly the same thing.

Grok?

···

--
Alex Combas
http://noodlejunkie.blogspot.com/

...

In this dictionary more than one variable is permitted to be bound to

the same object:
small_dog = house_cat = 'small domesticated carnivorous mammal'

In a real dictionary terms are bound to descriptions, but in the ruby
dictionary
of variables we would say terms are bound to objects, this boils down
to exactly the same thing.

Grok?

Seems pretty static and the emphasis is on the underlying objects
independant existence, which of course is very much
dependant on some live reference or it will be GC'd.

How would you explain?

a=a+1

Anyone who has written or studied the source code to an assembler knows the
basics of symbols.

Symbol Table
Id Table/Array
1 "word1"
2 "word2"
3 "word3"

Thus in some simple pseudo assembler

loads R1,"word1"
loads R2,"word2"
loads R3,"word1"

assembles to

loads 1,1
loads 2,2
loads 3,1

All new symbols are added to the symbol table, and symbols are only ever
referenced by Id. I'd guess that most modern VM's would behave in a similar
manner.

···

--

Alex Combas
http://noodlejunkie.blogspot.com/

--
Into RFID? www.rfidnewsupdate.com Simple, fast, news.

I don't know if this is what you are looking for, but this is how I
would explain:

Remember the variable 'a' is only a term.
Terms are bound to objects, and we find out which term
to which object by looking them up in a dictionary.

When we make a request (such as: a = a+1) for ruby to do
some operations with a variable ruby will do a quick look-up
in its dictionary to see which object is currently bound to that
term and then attempt to do whatever operations we have requested
upon on the object to which the term is bound.

I think this is somewhat similar to your assembler example.

···

On 1/7/06, Lyndon Samson <lyndon.samson@gmail.com> wrote:

How would you explain?

a=a+1

--
Alex Combas
http://noodlejunkie.blogspot.com/