Re: difference between :symbol and 'symbol
From: David Sletten (david_at_slytobias.com)
Date: 11/17/04
- Next message: Barry Margolin: "Re: Removing types"
- Previous message: Peter Seibel: "Re: difference between :symbol and 'symbol"
- In reply to: Rommel Martinez: "difference between :symbol and 'symbol"
- Next in thread: Kenneth Tilton: "Re: difference between :symbol and 'symbol"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Barry Margolin: "Re: Removing types"
- Previous message: Peter Seibel: "Re: difference between :symbol and 'symbol"
- In reply to: Rommel Martinez: "difference between :symbol and 'symbol"
- Next in thread: Kenneth Tilton: "Re: difference between :symbol and 'symbol"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|