Does ":" have an anolog in another language?

Sorry if anyone's beat me to this, I find it hard to keep up with such a busy list...

: is used to denote a symbol. The idea of a symbol has a rather broad interpretation, but I think that technically any identifier you make in a program -- a variable name or function name, for instance -- is a symbol.

Lisp languages have symbols in a similar sense that Ruby does, and they are usually used in much the same capacity as variable names -- they get evaluated into any binding they currently have to a function or piece of data. However, if quoted with a single quote (like 'this) they are left unevaulated and treated as the symbols themselves.

Lisp symbols don't have to start with :, but certain uses of them where they have semantic significance use that convention, which might be where Ruby borrows the syntax from. For example, a common idiom in Common Lisp is the associative list, where elements are alternated with symbols that must start with : and elements can be referenced by the :-symbol right before them. So you might have a list like (:a 1 :b 2 :c 3) called mylist, and (getf mylist :b) will return the 2. Similarly, :-symbols are used a lot in argument lists for many Common Lisp functions, to denote values meant to be passed to named parameters (aka keyword parameters).

I think there's also something like it in Smalltalk but I'm not sure.

So basically, a symbol is this little constant singleton identifier thing, that you can use to mean whatever :wink:

--ch--

···

-------------- Original message ----------------------
From: "Matt Todd" <chiology@gmail.com>

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.

Hi --

Sorry if anyone's beat me to this, I find it hard to keep up with
such a busy list...

: is used to denote a symbol. The idea of a symbol has a rather
broad interpretation, but I think that technically any identifier
you make in a program -- a variable name or function name, for
instance -- is a symbol.

Lisp languages have symbols in a similar sense that Ruby does, and
they are usually used in much the same capacity as variable names --
they get evaluated into any binding they currently have to a
function or piece of data. However, if quoted with a single quote
(like 'this) they are left unevaulated and treated as the symbols
themselves.

Ruby symbols aren't exactly used as variable names, though. If you
assign to a variable:

    a = 1

then Ruby creates and stores an :a symbol. But if you use the symbol
:a, like this:

   b = :a

there's no direct semantic connection to your variable called 'a'.

The way I usually think of it is: Symbols, like integers, are used
internally by Ruby. Also like integers, symbols are made available
for our use. But if the integer 3 is used somewhere in the
interpreter, and I use the integer 3 in a program, there's no direct
connection. The same is true of a symbol, such as :a.

David

···

On Sat, 29 Jul 2006, nothinghappens@mchsi.com wrote:

--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
Ruby for Rails => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

<nothinghappens@mchsi.com> wrote in message
news:072820061953.19665.44CA6B2700073D1500004CD1219791280203010CD2079C080C03BF9C020A9F9F0E08090207089B0102@mchsi.com...

Sorry if anyone's beat me to this, I find it hard to keep up with such a
busy list...

: is used to denote a symbol. The idea of a symbol has a rather broad
interpretation, but I think that technically any identifier you make in a
program -- a variable name or function name, for instance -- is a symbol.

Lisp languages have symbols in a similar sense that Ruby does, and they
are usually used in much the same capacity as variable names -- they get
evaluated into any binding they currently have to a function or piece of
data. However, if quoted with a single quote (like 'this) they are left
unevaulated and treated as the symbols themselves.

Lisp symbols don't have to start with :, but certain uses of them where
they have semantic significance use that convention, which might be where
Ruby borrows the syntax from. For example, a common idiom in Common Lisp
is the associative list, where elements are alternated with symbols that
must start with : and elements can be referenced by the :-symbol right
before them. So you might have a list like (:a 1 :b 2 :c 3) called
mylist, and (getf mylist :b) will return the 2. Similarly, :-symbols are
used a lot in argument lists for many Common Lisp functions, to denote
values meant to be passed to named parameters (aka keyword parameters).

I think there's also something like it in Smalltalk but I'm not sure.

So basically, a symbol is this little constant singleton identifier thing,
that you can use to mean whatever :wink:

--ch--

Doesn;t that therefore make it the same thing as a reference in c++ ? -Ike

In (Common) Lisp, every new word (loosely) the reader sees is interned
as a new symbol into the current package. But every word that begins
with a : is interned into a special package named "keyword", so
those are available as distinct, immediate, immutable identifiers
everywhere. They are usually called keyword symbols.

I heartily reccomend reading "Practical Common Lisp" (online at
http://www.gigamonkeys.com/book/\). Even if you don't plan on
programming in Lisp yourself, it will help you to understand a lot
about Ruby and programming in general too.

As Ruby started out as a simple Lisp dialect, that's certainly where
:symbols come from.

Jürgen

···

On Sat, Jul 29, 2006 at 04:53:25AM +0900, nothinghappens@mchsi.com wrote:

Sorry if anyone's beat me to this, I find it hard to keep up with such a busy list...

: is used to denote a symbol. The idea of a symbol has a rather broad interpretation, but I think that technically any identifier you make in a program -- a variable name or function name, for instance -- is a symbol.

Lisp languages have symbols in a similar sense that Ruby does, and they are usually used in much the same capacity as variable names -- they get evaluated into any binding they currently have to a function or piece of data. However, if quoted with a single quote (like 'this) they are left unevaulated and treated as the symbols themselves.

Lisp symbols don't have to start with :, but certain uses of them where they have semantic significance use that convention, which might be where Ruby borrows the syntax from. For example, a common idiom in Common Lisp is the associative list, where elements are alternated with symbols that must start with : and elements can be referenced by the :-symbol right before them. So you might have a list like (:a 1 :b 2 :c 3) called mylist, and (getf mylist :b) will return the 2. Similarly, :-symbols are used a lot in argument lists for many Common Lisp functions, to denote values meant to be passed to named parameters (aka keyword parameters).

--
The box said it requires Windows 95 or better so I installed Linux

No, because unlike a reference, a symbol doesn't actually refer to
anything. A symbol has no meaning other than that which you give it in
your head. A symbol is _just_ like a string except that (a) there's only
one instance of each, i.e., :foo is always the same symbol whereever it
is in the program whereas "foo" is different; and (b) they're immutable:
you can't ever change a symbol.

K.

···

On Sat, Jul 29, 2006 at 10:15:09AM +0900, Ike wrote:

Doesn;t that therefore make it the same thing as a reference in c++ ?

--
Keith Gaughan - kmgaughan@eircom.net - http://talideon.com/
So far as we are human, what we do must be either evil or good: so far
as we do evil or good, we are human: and it is better, in a paradoxical
way, to do evil than to do nothing: at least we exist.
    -- T. S. Eliot, essay on Baudelaire

I'm not sure what Matz would say about this. Although Lisp was
certainly one influence, it's pretty clear that Smalltalk was at
least, if not more so. One hint is the naming of the iterators in
enumerable, and the use of blocks. Not to mention the ruby object
model, which can be seen as another evolutionary step in the chain
started through Smalltalk-72, Smalltalk-76, and Smalltalk-80, with a
few capabilities of Self mixed in. Now, Lisp of course had a great
deal of influence on Alan Kay and Dan Ingalls in conceiving and
developing Smalltalk as well, but I don't think that it's accurate to
say that "Ruby started out as a simple Lisp dialect." As I understand
it started out as a scripting language which was completely
object-oriented in the way Kay intended when he coined the term. What
I sense as the family-tree of ruby, through the glasses of an old
Smalltalker, looks something like:

···

On 8/9/06, Jürgen Strobel <strobel@secure.at> wrote:

As Ruby started out as a simple Lisp dialect, that's certainly where
:symbols come from.

      +--------------------+
     / Perl -------\
   Lisp --> Smaltalk --\--> Ruby
                  \- Self -/

But that's an archaeological analysis, with a certain bias on my part.

--
Rick DeNatale

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/

Think of a uniquely identifiable, primary key in a database. You would
only refer to that row in that table with that one unique identifier,
right? Imagine that that id is 20. 20 is a pretty arbitrary value, and
can mean 20 people, 20 dollars, 20 minutes past 8, or even 20 the
number itself. That said, the meaning is determined by the context and
intention. Computers don't care too much about intention, and context
only when it has to, so 20 is what it is: a symbol referring to
something. In some cases, a string, in others, a number, and in fewer
circumstances, a symbol (in Ruby).

So, looking at 20 as a symbol (which would be created like... :"20"),
we'd be able to say that this symbol can represent anything, but it is
still the same thing. There is no need to create new instances of it
for the different contexts, really, because it still means nothing
apart from the context and the intention.

Back at the table, we can say that we want to mess with the row
identified by 20. This arbitrary value does not necessarily have an
immediate meaning on the rest of the data (in this example), but it
has meaning in that it identifies it. So, 20 can identify it in this
instance, and it won't in others.

But, what I really want to show is that the symbol, :"20", in ruby, is
always considered the symbol 20, and is not unique in any
circumstances. You mention the symbol :"20", and you will always use
the same symbol (as can be seen by its object id). It is all the same,
but, again, the context is what distinguishes its inherent value.

Of course, this is clear in my head: I hope I described it plainly
enough for you, though I feel somehow that I might not have.

M.T.

In Lisp,. the way I was explaining it, yes -- in the sense that they are
what Lisp uses for variables. In Ruby, they are more like the
occurrences of symbols in Lisp in which they typically start with a : --
they mean whatever you decide they mean. You might use them to index a
collection (e.g. a Hash) or you can assign them whatever semantic
meaning suits your intentions.

--ch--

···

On Sat, Jul 29, 2006 at 10:15:09AM +0900, Ike wrote:

> Doesn;t that therefore make it the same thing as a reference in c++ ?

And by the way the equivalent to

  :foo

in Smalltalk

is #foo

of course ruby would see this as a comment hence :foo instead

···

--
Rick DeNatale

I think I know :slight_smile:

Here's a quote from Matz, not sure where it originally came from. I
had it in some of my notes and possible presentations material.
If anyone knows this to be misattributed, please correct me:

···

On Fri, Aug 11, 2006 at 01:49:08AM +0900, Rick DeNatale wrote:

On 8/9/06, Jürgen Strobel <strobel@secure.at> wrote:

>As Ruby started out as a simple Lisp dialect, that's certainly where
>:symbols come from.

I'm not sure what Matz would say about this. Although Lisp was
certainly one influence, it's pretty clear that Smalltalk was at
least, if not more so. One hint is the naming of the iterators in
enumerable, and the use of blocks. Not to mention the ruby object
model, which can be seen as another evolutionary step in the chain
started through Smalltalk-72, Smalltalk-76, and Smalltalk-80, with a
few capabilities of Self mixed in. Now, Lisp of course had a great
deal of influence on Alan Kay and Dan Ingalls in conceiving and
developing Smalltalk as well, but I don't think that it's accurate to
say that "Ruby started out as a simple Lisp dialect." As I understand
it started out as a scripting language which was completely
object-oriented in the way Kay intended when he coined the term. What
I sense as the family-tree of ruby, through the glasses of an old
Smalltalker, looks something like:

     +--------------------+
    / Perl -------\
  Lisp --> Smaltalk --\--> Ruby
                 \- Self -/

But that's an archaeological analysis, with a certain bias on my part.

--
Rick DeNatale

-----
Ruby is a language designed in the following steps:

  * take a simple lisp language (like one prior to CL).
  * remove macros, s-expression.
  * add simple object system (much simpler than CLOS).
  * add blocks, inspired by higher order functions.
  * add methods found in Smalltalk.
  * add functionality found in Perl (in OO way).

So, Ruby was a Lisp originally, in theory.
Let's call it MatzLisp from now on. :wink:

                                                        matz.
-----

So yes, he explicitly started with something Lisp like, and added
Smalltalk's object model along with Perl's good stuff. If I had to add
anoher language there I would say C, because even if Ruby is very
different from C a lot of C-isms (or POSIX-isms) shine through where
Ruby is just a layer over the C std. library.

-Jürgen

--
The box said it requires Windows 95 or better so I installed Linux

As far as an analogue in other languages, I tend to think of symbols
sortof like old-style C defines.

#define HAS_EGGS 1
#define CAN_FRY 2
add_property(HAS_EGGS);
add_property(CAN_FRY);

...or y'know something like that. Its a constant that has some
meaning, but all you really care about is it's unique.

add_property(:has_eggs)
add_property(:can_fry)

But all the #defines and stuff are automatic. You could use strings,
sure, but just like in C, I sortof get this sickly feeling when I use
(slow) strings when I don't have to. This explanation skips over all
the crazy OO stuff you can do with symbols, but I'd say thats the
closest thing you can get to their equivalent in another language.

···

On 7/29/06, Charles Hoffman <nothinghappens@mchsi.com> wrote:

> On Sat, Jul 29, 2006 at 10:15:09AM +0900, Ike wrote:
>
> > Doesn;t that therefore make it the same thing as a reference in c++ ?

In Lisp,. the way I was explaining it, yes -- in the sense that they are
what Lisp uses for variables. In Ruby, they are more like the
occurrences of symbols in Lisp in which they typically start with a : --
they mean whatever you decide they mean. You might use them to index a
collection (e.g. a Hash) or you can assign them whatever semantic
meaning suits your intentions.

--ch--

Here's a quote from Matz, not sure where it originally came from. I
had it in some of my notes and possible presentations material.
If anyone knows this to be misattributed, please correct me:

That's from a mailing list post, here's a link (I believe) works:
http://groups.google.com/group/comp.lang.ruby/msg/6c885c3e11445122

···

On 8/11/06, Jürgen Strobel <strobel@secure.at> wrote:

-----
Ruby is a language designed in the following steps:

  * take a simple lisp language (like one prior to CL).
  * remove macros, s-expression.
  * add simple object system (much simpler than CLOS).
  * add blocks, inspired by higher order functions.
  * add methods found in Smalltalk.
  * add functionality found in Perl (in OO way).

So, Ruby was a Lisp originally, in theory.
Let's call it MatzLisp from now on. :wink:

                                                        matz.
-----

So yes, he explicitly started with something Lisp like, and added
Smalltalk's object model along with Perl's good stuff. If I had to add
anoher language there I would say C, because even if Ruby is very
different from C a lot of C-isms (or POSIX-isms) shine through where
Ruby is just a layer over the C std. library.

-Jürgen

--
The box said it requires Windows 95 or better so I installed Linux

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iQEVAwUBRNyGTfy64gyiEfXtAQKjwggAiazPml+V9ohzu/wTO4aCgqwDii8n/o99
EaZFbIa4bGGRN3dHa7rvtqJjLcWlwuT3ll310SIrYUQBY8wrICqqmNlfnwMSchPl
k6ge7CHoC8RQZ9/1kuh1xgifi3QP5EwovNCYKhfrQ14I7DSicO5njyFzVQiZ9EJB
N7sE265Lz8/6D/R9l9ODSR+Eysq2tZVESxKkUxDVedIewxNZNF+bFHM4lyQOCSm8
fMKVNB5NwBVMyWvxKTWoUy4OtOif/v129GrDSqtMIaj6qvJWwYl98rRy+pcF0w5J
2WeL1E08pbIE4BMprMI63ngxd3pzy1ks/iJf06l7xe2Wt4aM/k3VRQ==
=DhIi
-----END PGP SIGNATURE-----

--
- Simen

I hadn't thought of that, but much of the typical usage is somewhat
similar. But Ruby's symbols can also be used to refer to an existing
attribute or method by name... you see a lot of that sort of thing in
_why's stuff.

--ch--

···

On Sun, 2006-07-30 at 17:52 +0900, Aleks Kissinger wrote:

As far as an analogue in other languages, I tend to think of symbols
sortof like old-style C defines.

#define HAS_EGGS 1
#define CAN_FRY 2
add_property(HAS_EGGS);
add_property(CAN_FRY);

Hi --

As far as an analogue in other languages, I tend to think of symbols
sortof like old-style C defines.

#define HAS_EGGS 1
#define CAN_FRY 2
add_property(HAS_EGGS);
add_property(CAN_FRY);

I hadn't thought of that, but much of the typical usage is somewhat
similar. But Ruby's symbols can also be used to refer to an existing
attribute or method by name... you see a lot of that sort of thing in
_why's stuff.

True, but only if the method that uses them takes a symbol. For
exapmle, when you do:

   obj.method(:x)

the use of the symbol for the method's name isn't what gets you access
to the method object. In fact, most of the Ruby methods that take
symbols also take strings:

   obj.method("x")

So it depends on what a given method does with its arguments.

David

···

On Mon, 31 Jul 2006, Charles Hoffman wrote:

On Sun, 2006-07-30 at 17:52 +0900, Aleks Kissinger wrote:

--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
Ruby for Rails => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.