Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does |5E| mean in Common Lisp?

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]
like image 330
john Avatar asked Jul 01 '10 04:07

john


People also ask

What does #' mean AutoLISP?

#'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 .

How do you compare symbols in a Lisp?

You can use string= to compare symbol names as well as strings.

What is #' used in Lisp?

to indicate the functional value of a symbol or of an expression, Lisp uses the special form (function fn) , which is commonly abbreviated as #' .

What does colon mean in Lisp?

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.


2 Answers

|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.

like image 130
Rainer Joswig Avatar answered Oct 04 '22 22:10

Rainer Joswig


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.

like image 34
Gabe Avatar answered Oct 04 '22 23:10

Gabe