For example, #'functionname
, is it necessary?
相关问题
- What does an “empty line with semicolon” mean in C
- Generating powerset in one function, no explicit r
- Drakma and Dexador both fails at USocket call whil
- Is it possible to put only one option on a ternary
- JavaScript, confusing syntax when declaring a vari
相关文章
- What is the meaning of this syntax?
- How can I write-protect the Matlab language?
- Does learning one Lisp help in learning the other?
- Why the enum constants must be declared before any
- Common Lisp: Why does my tail-recursive function c
- What is the definition of “natural recursion”?
- How do I write a macro-defining macro in common li
- How can I unintern a qualified method?
#'functionname in Common Lisp
Common Lisp and some other Lisp dialects have more than one namespace. Here the ones for functions and values are different. To get the function value of a name, we need to write:
Since that is a bit long to write, there is a shorter notation:
To show the effect see this:
Above defines a local variable
FOO
and a local functionFOO
. The list statement returns the value ofFOO
, then the function value offoo
using the(function ...)
notation, then the same using the short hand notation and then the value of actually calling the functionFOO
.(function foo)
and#'foo
are the same concept, but written differently. Both refer to the local lexical function namedFOO
.FOO
is introduced by theFLET
form as a local function.The Lisp REPL returns something like this:
Above shows that the first item is really the value of the variable
FOO
and the next two items are the function values, the function bound toFOO
. The last item is the symbolBAR
, as returned from the function call(FOO)
.This separation of namespaces for normal values and function values is present in Common Lisp, Emacs Lisp and ISLisp. Other Lisp dialects like Scheme don't have that separation. In Scheme a name can only denote one value.
The # character.
The
#
character is used to introduce special syntax in s-expressions. Here are some examples:and many more.
#
is a so-called dispatching macro character.The ANSI Common Lisp HyperSpec describes the
#
character in Section 2.4.8 Sharpsign.Common Lisp could have used a different syntax for vectors. Say
[1 2 3]
. It also could have used a different syntax for complex numbers. Something like{1 2}
. But it does not do that. Why? The reason is because Common Lisp tries to be economical with character usage in the language and leaves characters like[
,]
,{
and}
to the user for his/her own syntax extensions. Often Lisp users develop embedded languages and to make that a bit easier, the Common Lisp standard tries to keep character usage down to a minimum and also provides the mechanism of macro characters and dispatch macro characters.To keep character usage down, a single dispatch character
#
is used and the next character then determines what can be denoted.#b
for binary numbers.#x
for hex numbers.#c
for complex numbers.#(
for vectors.#'
for function names. Plus many more.Since Common Lisp is a programmable programming language, this character level syntax can be changed by the user. See the function SET-DISPATCH-MACRO-CHARACTER.