-
Notifications
You must be signed in to change notification settings - Fork 2
symbol
TurtleKitty edited this page May 10, 2019
·
4 revisions
A symbol is an interned string of characters - like a text, but without quotes.
They are used as identifiers for variables and object methods.
When used naked in code, they name another object.
When quoted, they name themselves.
Due to the dot operator, periods (.) can not be used in symbols.
(def foo 7)
foo ; 7
(quote foo) ; foo
'foo ; foo
(symbol? x)
(def foo 7)
(symbol? foo) ; false - the unquoted symbol foo is evaluated,
; returning 7, which is not a symbol
(symbol? (quote foo)) ; true
(symbol? 'foo) ; true
(symbol? 'x) ; true
(symbol? 1) ; false
(symbol? "foo") ; false
(symbol? null) ; false
(symbol? true) ; false
(def foo 'bar)
foo ; bar
foo.type ; (symbol)
foo.to-bool ; true
foo.to-text ; "bar"