Content deleted Content added
Grammar fix. Tags: Mobile edit Mobile web edit |
Filled in 3 bare reference(s) with reFill 2 |
||
Line 56:
A symbol in [[Lisp (programming language)|Lisp]] is unique in a [[namespace]] (or ''package'' in [[Common Lisp]]). Symbols can be tested for equality with the function EQ. Lisp programs can generate new symbols at runtime. When Lisp reads data that contains textual represented symbols, existing symbols are referenced. If a symbol is unknown, the Lisp reader creates a new symbol.
In Common Lisp symbols have the following attributes: a name, a value, a function, a list of properties and a package.<ref>
In Common Lisp it is also possible that a symbol is not interned in a package. Such symbols can be printed, but when read back, a new symbol needs to be created. Since it is not ''interned'', the original symbol can not be retrieved from a package.
In Common Lisp symbols may use any characters, including whitespace, such as spaces and newlines. If a symbol contains a whitespace character it needs to be written as |this is a symbol|. Symbols can be used as identifiers for any kind of named programming constructs: variables, functions, macros, classes, types, goto tags and more.
Symbols can be interned in a package.<ref>
====Examples====
Line 113:
===Ruby===
In [[Ruby (programming language)|Ruby]], symbols can be created with a literal form, or by converting a string.<ref name=pickaxe />
They can be used as an identifier or an interned string.<ref name="rubysymbol">{{cite web |last=Kidd |first=Eric |date=20 January 2007 |title=13 Ways of Looking at a Ruby Symbol |url=http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol#9 |work=Random Hacks |access-date=10 July 2011}}</ref> Two symbols with the same contents will always refer to the same object.<ref>{{Cite web
It is considered a [[best practice]] to use symbols as keys to an [[associative array]] in Ruby.<ref name=rubysymbol /><ref name="wrongreason">{{cite web|title=Using Symbols for the Wrong Reason|url=http://microjet.ath.cx/WebWiki/2005.12.27_UsingSymbolsForTheWrongReason.html|work=Gnomic Notes}}</ref>
|