Hello, all!
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]
Hello, all!
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]
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
.
|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.