3 ms·
The only Lisp I know is Racket (basically Scheme), so take the following with a grain of salt. '(foo bar baz) is almost the same thing as (list foo bar baz). H
by RaphiePS 14y ago
The only Lisp I know is Racket (basically Scheme), so take the following with a grain of salt.
'(foo bar baz) is almost the same thing as (list foo bar baz). However, ' also makes the contents of the list into symbols, not variable references. Basically, '(foo bar baz) returns (list 'foo 'bar 'baz), not a list containing the values of the variables foo, bar, and baz.
Symbols aren't much like strings. They're immutable, and actually just refer to a unique number, not characters. I hope that sort of makes sense!
- nivertech 14y ago'(foo bar baz) is sugar for (quote (foo bar baz)) list function unlike quote will evaluate it's arguments, i.e. user=> (quote (a b c)) (a b c) user=> '(a b c) (a b c) user=> (list a b c) CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:1) user=> (list 'a 'b 'c) (a b c)
- randallsquared 14y ago> Symbols aren't much like strings. They're immutable, and actually just refer to a unique number, not characters. Depending on language, that could make them exactly like strings. :)
- derleth 14y agoIf you have immutable strings and a smart compiler, yes, you could indeed have strings and symbols that are functionally identical. In fact, in Old Lisp, there were no strings and symbols were used for everything we use strings for now; that lead to weak string handling and it's why Common Lisp and all modern Lisp variants have a string type.