4 ms·
> Calling Symbol() creates a new symbol, a value that’s not equal to any other value. Lisp: CL-USER 1 > (eq (make-symbol "Foo") (make-symbol "Foo")) N
by lispm 11y ago
> Calling Symbol() creates a new symbol, a value that’s not equal to any other value.
Lisp:
CL-USER 1 > (eq (make-symbol "Foo") (make-symbol "Foo"))
NIL
> Symbols aren’t exactly like anything else
CL-USER 2 > (type-of (make-symbol "Foo"))
SYMBOL
> Trying to concatenate a symbol with strings will result in a TypeError.
CL-USER 3 > (concatenate 'string "abc" 'foo "def")
Error: In a call to LENGTH: FOO (of type SYMBOL) is not of type SEQUENCE.
> There are three ways to obtain a symbol.
> Call Symbol()
(make-symbol "FOO")
> Call Symbol.for(string)
(find-symbol "FOO")
Other than that symbols in Common Lisp have a package, a value, a function and a property list. Symbols can be interned in a package or not. So-called Keyword symbols are in the package KEYWORD and have itself as the value. :I-AM-A-KEYWORD evaluates to :I-AM-A-KEYWORD.
- drudru11 11y agoThat first example with 'eq is a little surprising to me. Previous to your post, I believed that Common Lisp symbols were equivalent to Lisp atoms. That is, I just thought of symbols as a way of interning strings (like Smalltalk, Objc, Ruby, etc.) ES6 Symbols reminded me of gensym. I didn't expect to see ES6 having the same behaviour as Common Lisp! Thanks for posting.