Re: difference between :symbol and 'symbol

From: David Sletten (david_at_slytobias.com)
Date: 11/17/04


Date: Wed, 17 Nov 2004 03:58:33 GMT

Rommel Martinez wrote:
> Hi, what is the real difference between :symbol and 'symbol?
>
What you mean to ask is what is the difference between :SYMBOL and
SYMBOL. The single quote in your second example is not part of SYMBOL,
it's just a shortcut for (quote symbol). (More on that in a moment.)

The short answer is that :SYMBOL is a keyword. Keywords are constants
which evaluate to themselves:
:symbol => :SYMBOL
Keywords are used in many functions to specify certain optional
arguments known for obvious reasons as 'keyword arguments':
(make-string 3 :initial-element #\z) => "zzz"

Symbols in general can be used as names of variables or functions, among
other things:
(defvar symbol 9)
When used to represent a variable, a symbol evaluates to the value of
the variable:
symbol => 9
(Of course, this is a silly name for a variable).
If you want to refer to a symbol itself rather than its value ('mention'
rather than 'use') you can quote it:
(quote symbol) => SYMBOL
As I mentioned above, the following does the same thing:
'symbol => SYMBOL
Note that we can also quote a keyword, but it's pointless:
':symbol => :SYMBOL

The longer answer is that :SYMBOL is an external symbol in the package
KEYWORD. Its fully-qualified name is KEYWORD::SYMBOL. SYMBOL, on the
other hand, is (by default) located in the package COMMON-LISP-USER, so
its full name is COMMON-LISP-USER::SYMBOL. Try:
(describe 'keyword::symbol) and
(describe 'symbol) (The same as (describe 'common-lisp-user::symbol)).

Keywords exhibit the special properties mentioned above by virtue of
their presence in the package KEYWORD.

David Sletten



Relevant Pages

  • Re: Help needed on creating a subform
    ... Don't enter anything in this procedure yet but scroll down below the End Sub ... "ORDER BY QuoteId DESC, Keyword" ... based on the current value of the quote id. ... A UNION query concatenates the results of two separate queries. ...
    (microsoft.public.access.forms)
  • Re: Help needed on creating a subform
    ... entering data I find I need to add a new keyword to the list, ... I want to eventually to have the quote form as the ... the update keywords button, or even have this happen automatically ... maintenance form, keyword maintenance form. ...
    (microsoft.public.access.forms)
  • RE: Help needed on creating a subform
    ... need a main form bound in some way to your Quote table. ... design your single form bound to the Quote table. ... Next design a continuous form bound to your KeywordLink table. ... SELECT KeywordId, Keyword FROM Keyword ORDER BY Keyword ...
    (microsoft.public.access.forms)
  • What is "Quote" ?
    ... What is the meaning of "Quote" keyword? ... Jack ...
    (microsoft.public.vb.general.discussion)
  • Re: access closure variable
    ... (lambda (command &optional args) ... Keywords are not really package independent. ... :FOO ... The reader will read:foo as a symbol in the keyword package. ...
    (comp.lang.lisp)