[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

does ":" have an anolog in another language?

Ike

7/28/2006 6:39:00 PM

does the colon operator have an anolog in say, Java or C++ ? It seems to be
a reference pointer. Am i mistaken in assuming this? Thanks, Ike


27 Answers

Chad Perrin

7/28/2006 6:55:00 PM

0

On Sat, Jul 29, 2006 at 03:40:11AM +0900, Ike wrote:
> does the colon operator have an anolog in say, Java or C++ ? It seems to be
> a reference pointer. Am i mistaken in assuming this? Thanks, Ike

I tend to guess you're referring to uses of the : character such as the
following . . .

foo = { :bar => "baz" }

If that's what you mean, it's not an operator. Rather, it's a sigil,
used to denote a symbol. Symbols are subtle things, and last time I
personally saw them discussed and defined on ruby-talk it turned into a
flamewar. I recommend googling for "ruby symbol" (without the quotes)
and reading about them thusly.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"The ability to quote is a serviceable
substitute for wit." - W. Somerset Maugham

Matt Todd

7/28/2006 7:18:00 PM

0

A simple way to describe it may be to look at it as a singleton object
in that, every unique symbol is a different object, but all of the
same symbols are the same object.

For instance...

x = Foo.new('bar')
y = Foo.new('bar')
z = Foo.new('baz')

Both x and y will be the same object, but different references. But z
will be different because its value is different. The only way I can
think of reproducing this in any other language is to create this
weird version of a Singleton class. Should we call it a
Unique-Singleton pattern?

M.T.

Tim Hunter

7/28/2006 7:24:00 PM

0

Ike wrote:
> does the colon operator have an anolog in say, Java or C++ ? It seems to be
> a reference pointer. Am i mistaken in assuming this? Thanks, Ike
>
>
Tokens that start with colon are called "symbols".

Check out the Symbol class at ruby-doc: http://www.ruby-doc...

Chad Perrin

7/28/2006 7:26:00 PM

0

On Sat, Jul 29, 2006 at 04:18:28AM +0900, Matt Todd wrote:
> A simple way to describe it may be to look at it as a singleton object
> in that, every unique symbol is a different object, but all of the
> same symbols are the same object.
>
> For instance...
>
> x = Foo.new('bar')
> y = Foo.new('bar')
> z = Foo.new('baz')
>
> Both x and y will be the same object, but different references. But z
> will be different because its value is different. The only way I can
> think of reproducing this in any other language is to create this
> weird version of a Singleton class. Should we call it a
> Unique-Singleton pattern?

I'm perfectly happy with "object-oriented symbol", but that might be
because Ruby is (100%-ish) object-oriented, and I knew about symbols in
the Lisp idiom before encountering Ruby. Ruby symbols really do just
appear to be the same thing as Lisp symbols, except you can send them
messages in the Ruby idiom.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Brian K. Reid: "In computer science, we stand on each other's feet."

Matt Todd

7/28/2006 7:45:00 PM

0

@Chad:

Yep, that's about it, as far as I can tell.

dblack

7/28/2006 8:06:00 PM

0

dblack

7/28/2006 8:07:00 PM

0

Ara.T.Howard

7/28/2006 8:12:00 PM

0

Chad Perrin

7/28/2006 8:27:00 PM

0

On Sat, Jul 29, 2006 at 05:07:16AM +0900, dblack@wobblini.net wrote:
> On Sat, 29 Jul 2006, Chad Perrin wrote:
> >
> >I'm perfectly happy with "object-oriented symbol", but that might be
> >because Ruby is (100%-ish) object-oriented, and I knew about symbols in
> >the Lisp idiom before encountering Ruby. Ruby symbols really do just
> >appear to be the same thing as Lisp symbols, except you can send them
> >messages in the Ruby idiom.
>
> I'd just call them symbols, or Symbol objects (just as with strings,
> arrays, etc.).

Even better -- more succinct, makes the same point. Thanks.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.

Chad Perrin

7/28/2006 8:29:00 PM

0

On Sat, Jul 29, 2006 at 05:11:35AM +0900, ara.t.howard@noaa.gov wrote:
> On Sat, 29 Jul 2006 dblack@wobblini.net wrote:
>
> >I'd just call them symbols, or Symbol objects (just as with strings,
> >arrays,
> >etc.).
>
> i like 'symbol literal' as in
>
> array literal => [42]
> hash literal => {42=>42}
> symbol literal => :foo

. . except that doesn't point out the object-orientedness of it. The
reason I brought up attaching something related to object oriented
programming to the word "symbol" was as a means of contrasting with an
older and, in many cases, better-known use of "symbols" in programming
(a use that is, in fact, almost identical except for that pesky OO-ness
of Ruby).

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall