Re: 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

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:


-------------- Original message ----------------------
From: “Matt T.” [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs