[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: On Symbols

Dave Howell

1/4/2006 10:06:00 PM


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?

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....

"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.

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...

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.

In this case a Ruby symbol is similar to a Lisp keyword symbol

Is a Lisp keyword symbol different than a Lisp symbol?

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

Sometimes?

However, in Lisp a symbol has much greater functionality.
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.")

In briefest, my understanding of symbol in Ruby is that it is an
interned string used as a name
("interned" meaning that it is entered into memory as a single, atomic
entity, a monad -
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.




8 Answers

Dave Howell

1/4/2006 10:47:00 PM

0


On Jan 4, 2006, at 14:06, Dave Howell wrote:

>
> 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?

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

'You are sad,' the Knight said in an anxious tone: 'let me sing you a
song to comfort you.'
'Is it very long?' Alice asked, for she had heard a good deal of
poetry that day.
'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--'
'Or else what?' said Alice, for the Knight had made a sudden pause.
'Or else it doesn't, you know. The name of the song is called
"HADDOCKS' EYES."'
'Oh, that's the name of the song, is it?' Alice said, trying to feel
interested.
'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."'
'Then I ought to have said "That's what the SONG is called"?' Alice
corrected herself.
'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!'
'Well, what IS the song, then?' said Alice, who was by this time
completely bewildered.
'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!



Ross Bamford

1/4/2006 11:01:00 PM

0

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....
>
> "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.
>

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...

--
Ross Bamford - rosco@roscopeco.remove.co.uk

dblack

1/4/2006 11:13:00 PM

0

Jim Weirich

1/5/2006 12:50:00 AM

0

DAB wrote:
> 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.

True, but ...

> [...] 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.

I think that this second statement is much more important than the
first. The fact that 1073741823 is direct and 1073741824 is a reference
makes very little difference 99.99% of the time.

Understanding that Fixnums, Symbols and the such are direct is good for
groking implementation details, but provides little insight in using
Ruby. The fact we can pretend that everything is a reference is a
marvelous feature of the Ruby object model.

Just MHO.

--
-- Jim Weirich

--
Posted via http://www.ruby-....


dblack

1/5/2006 12:58:00 AM

0

Chad Perrin

1/5/2006 2:21:00 AM

0

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....
>
> "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.

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.

--
Chad Perrin [ CCD CopyWrite | http://ccd.ap... ]

print substr("Just another Perl hacker", 0, -2);


Gary Wright

1/5/2006 4:08:00 AM

0


On Jan 4, 2006, at 7:49 PM, Jim Weirich wrote:
> The fact we can pretend that everything is a reference is a
> marvelous feature of the Ruby object model.

+1

In fact I think of Fixnum and Symbol literals as
just special variables pre-bound to references to particular
objects in the way that uninitialized instance variables
are pre-bound to the nil object, but unlike variables you
can't vary the binding. I'd call them constants but then
everyone would get confused with that whiny group of variables
that start with an uppercase letter and then complain every-
time something changes.

Gary Wright



mercedes goldman

1/15/2010 8:09:00 PM

0


> Dude,Howardprefers not being in the public eye. Of course being a
> public figure goes with the territory of what he does, but again, and
> this part also is not up for discussion, he absolutely 100% prefers to
> maintain the lowest profile possible away from the show.
>

With all respect to you guys, this comment is pretty funny. Who else
has ever done a full-feature movie like 'Private Parts'?
Of course after the book and the movie, Howard then decided he wanted
some privacy. Too funny.

Speaking of the movie, Howard should have Paul 'Pig Vomit' Giamatti go
on Conan with him. Am I the only one who thinks Zucker is the
reincarnation of Pig Vomit?

Kimmel (and Conan, if they don't pull the plug on the set) should re-
run of Giamatti's Pig Vomit performance from Private Parts. Now that
would be funny.

Say NNN-bc