-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2005.12.29 23:37, Yohanes Santoso <ysantoso-rubytalk / dessyku.is-a-geek.org> wrote: > Eero Saynatkari <ruby-forum-reg / mailinator.com> writes: > > > Yohanes Santoso wrote: > >> Alex Knaub <aknaub / gmail.com> writes: > >> > >>> 2005/12/28, Surgeon <biyokuantum / gmail.com>: > >>>> Hi, > >>>> > >>>> I am a Ruby newbie. I wish I didn't post such a simple question here > >>>> but I had to. > >>>> What is the difference between :foo (a keyword) and "foo"(a string). > >>>> Can they be used interchangeably? Are they fundamentally same and is > >>>> the only difference performance? > >>> > >>> http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red > >> > >> What a coincidence. Seems like Jim and I finally had enough of people > >> conflating symbols and immutable strings on the same day. > >> > >> http://microjet.ath.cx/WebWiki/2005.12.27_UsingSymbolsForTheWrongReason.html > > > > While, technically speaking, both of you are absolutely and > > undeniably correct (with one correction: Symbols are not Strings), > > such a conflation is the best way to get someone over the > > initial confusion. > > The initial confusion is simply part of the learning curve rubyists > must go through along with learning that 'everything' is an > object. Dumbing down the situation can bring unexpected result: > > Since we are around Christmas, I'm going to use Santa Claus as an > example. To prevent the initial confusion of children finding presents > magically appearing before Christmas tree, parents resort to such > outlandish notion that that is the work of a joyful guy who has never > heard of razor in a red jumper suit and riding reinders-pulled sleigh > around the world in one night. > > Some children outgrew that notion. Some don't. Those that don't would > either sulk for a long time about the demise of such a joyful guy, or > start to think their parents are liars and spend the next untold years > of their life learning enough Math and Physics to prove that it is > impossible for a guy like Santa Claus to visit all children in one > night. Yes, I like the rationale presented. Perhaps I should have worded differently: conflating Symbols with immutable strings (not Strings) makes it easier to understand their function in ruby. Any ambiguity resulting from this is far easier to correct than it is the assumption that Symbols are identifiers or references or variables (rather than values, which is the first thing anyone needs to know about Symbols). > > As this thread quite well demonstrates, > > a definition for Symbols is quite difficult to come up with. > > A formal definition is difficult to formulate correctly, but what CLHS > has is good enough: > > "Symbols are used for their object identity to name various entities > in Common Lisp, including (but not limited to) linguistic entities > such as variables and functions." -- > http://www.lisp.org/HyperSpec/Body/syscla_symbol.html#symbol This makes no sense to someone just starting. > It is just a way to name/identify things. In RL, you name/identify > that collection of atoms 'bird', and another collection of atoms > 'cow'. In ruby, you name/identify an object 'host', and another object > 'port'. Just as you name parts of collection of atom that you named > 'bird' 'wings', 'legs', 'feathers', etc., you name parts of a > Hashtable that you named 'ServerConfig' 'host', 'port'. This makes sense but, as you notice, you are using 'strings' in your explanation :) > Just as one does not dumbed down "'everything' is an object in ruby", > which is a powerful ability, one should not dumbed down "symbols are > user-defined identifiers". It's just parts of learning curve. Very good until this part. Symbols, most empathically, are *not* identifiers (and I am quite sure this was merely a mistype/-thought on your part). > > To paraphrase fifteen thousand fourty-three mediocre > > comedians over the last three centuries: > > > > "A Symbol is like a word, a sentence, a phrase, a > > description or, perhaps, a name. Except sometimes." > > > > > >> YS. E - -- "That sort of thing happens in bath tubs maybe. Not in real life." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDtEyGxvA1l6h+MUMRAnowAJsEyO25UhFG6VF6RbDZbzQ1XpKMWACfcEd4 HpUQm6vCasi8Yg5UPkzfAqE= =hXPD -----END PGP SIGNATURE-----