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