The Little Schemer 4e by Friedman and Felleisen starts out by defining atom?:
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
Then in the first chapter there's questions asking if so and so is a atom or not. E.g. (the footnote is rephrased for clarity):
Is it true that this is an atom?
atom**in Scheme:
(quote atom)or'atom
It says turkey, 1492, u, and *abc$ are also atoms.
All of these except 1492 must be preceded by a ' - otherwise we get a Error: execute: unbound symbol:
1492 and '1492 both work. Henceforth, in this book, how do I know when something should or should not be preceded by a quote (')??? It's confusing. I wish the authors had just been explicit with the quotes -- does it really add that much visual noise to have a single quote (') precede expressions??? Should I just assume everything is preceded by a quote (')?
Atoms. An atom is an indivisible thing. A value like
13or72is indivisible, it is a single value. There are other atoms, a string like"hello", a variable likexory, a value like:keywordor'something.When Lisp is written, atoms are separated by spaces or parentheses. We can then create one or more
formby putting atoms within parentheses, for example(* 2 (+ 1 3)). The atoms here are:There are then a couple of problems. For starters, with
xdo we mean the atom'x, a variable calledx, or the value stored within the variablex? Lisp assumes thatxis a variable and so typingxreturns the value ofxor produces an error aboutxbeing unbound. Putting a single quote in front ofx, as'x, says "please don't try to evaluate this".Forms have a consistent format
(operator data1 data2 data3 ...). But what happens if you just want to supply data? What operator do you use? The answer is to use operatorquote, which evaluates the form to just the data. Because saying quote all of the time is annoying, Lisp allows you to say'(data1 data2 data3 ...)instead.As for
'1492, this is the same as1492in Scheme and Common Lisp. The values are interchangeable. I would use1492since the quote is superfluous.