From: "Jürgen Strobel" Date: 2006-08-09T23:57:36+09:00 Subject: Re: does ":" have an anolog in another language? --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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... >=20 > : is used to denote a symbol. The idea of a symbol has a rather broad in= terpretation, but I think that technically any identifier you make in a pro= gram -- a variable name or function name, for instance -- is a symbol. >=20 > Lisp languages have symbols in a similar sense that Ruby does, and they a= re usually used in much the same capacity as variable names -- they get eva= luated 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 unevaul= ated and treated as the symbols themselves. >=20 > Lisp symbols don't have to start with :, but certain uses of them where t= hey have semantic significance use that convention, which might be where Ru= by 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 th= em. So you might have a list like (:a 1 :b 2 :c 3) called mylist, and (get= f mylist :b) will return the 2. Similarly, :-symbols are used a lot in arg= ument lists for many Common Lisp functions, to denote values meant to be pa= ssed to named parameters (aka keyword parameters). >=20 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=FCrgen --=20 The box said it requires Windows 95 or better so I installed Linux --YZ5djTAD1cGYuMQK Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iQEVAwUBRNn32vy64gyiEfXtAQIMvAgA68bSFdfnTVRXv38rRo3iRPY/epf3oC0f cU23asMyPUYJHP5nBFvm2KnMxNjTQYs53+wo9265064puKphZ+/x1fKgMikaXU+A Hlv5CcNbQvU+am9oRGrzpYck7PJFdneY2nbBPssUHhGj0scDGxfHCL9g8xJmXXqp NNGMQteD0+rJJu5l0auTC4HKDxJWVOa5WAZQd09uzz3h89ubq0dWOrWmFKf47l47 0gIG7ahq50I94tc2kTpHlwY/3bdV4Qx7WlmfSGiDEaWb92weNJXvroeu6pICK5Cf t69gy2HqpxSHwNpoC0EvQRFnP5v4TI56J7k7CBTMP84/q4ikhC4XJg== =UKr8 -----END PGP SIGNATURE----- --YZ5djTAD1cGYuMQK--