I got following error message in Common Lisp.
What does || mean in CL?
CL-USER> (write-to-string 5e)
The variable |5E| is unbound.
[Condition of type UNBOUND-VARIABLE]
#'functionname in Common Lisp Above defines a local variable FOO and a local function FOO . The list statement returns the value of FOO , then the function value of foo using the (function ...) notation, then the same using the short hand notation and then the value of actually calling the function FOO .
You can use string= to compare symbol names as well as strings.
to indicate the functional value of a symbol or of an expression, Lisp uses the special form (function fn) , which is commonly abbreviated as #' .
In Common Lisp generally symbols can be in a package (kind of a namespace). An unexported symbol bar in a package foo is written as foo::bar . The double colon is between the package name and the symbol name. An exported symbol then is written as foo:bar . A single colon is used.
|foo| is just a printed representation for symbols. 5e does not read as a number by default, so it is a symbol and may be printed as |5E|. One can use it also to have all kinds of characters in symbols, including whitespace. |this is a symbol, isn't it?| - it is!
CL-USER > (describe '|this is a symbol, isn't it?|)
|this is a symbol, isn't it?| is a SYMBOL
NAME "this is a symbol, isn't it?"
VALUE #<unbound value>
FUNCTION #<unbound function>
PLIST NIL
PACKAGE #<The COMMON-LISP-USER package, 798/1024 internal, 0/4 external>
Note also that Common Lisp uses uppercase symbols by default. Symbols read will be uppercased. So the symbol foo is read and then has a symbol name "FOO". To denote a symbol with lowercase or mixed case letters, one can use |foo|. If you create a lowercase symbol with something like (intern "foo"), then it also will be printed as |foo|. If you create an uppcase named symbol with something like (intern "FOO"), then it will be printed as foo. That's the reason why 5e prints as |5E| with an uppercase E.
If you have a symbol, you can get its name as a string with the function SYMBOL-NAME.
You can read an integer from a string with he function PARSE-INTEGER. It has a keyword parameter :RADIX, where you can provide the radix for reading.
CL-USER > (parse-integer (symbol-name '5e) :radix 16)
94
Otherwise use hex numbers like #x5e or change the read base.
Frank Shearar points out the documentation in the Common Lisp HyperSpec: 2.3.4 Symbols as Tokens.
It's using those characters as quotes. It is trying to interpret 5e
as a name of a variable. My guess is that you really want it to interpret it as a hex number, so it should probably be #x5e
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With