问题
I've just started reading The Little Schemer. It starts off with several questions asking if a given expression is an atom. It's pretty straightforward but, funny enough, the very first question is throwing me off a bit. It asks:
Is it true that this is an atom?
atom11(quote atom) or ’atom
What's throwing me off is the footnote reference. They're asking if atom is an atom, but then somehow they're saying that atom is really (quote atom) or ’atom? I just don't get it.
回答1:
What’s going on here is Friedman was trying to avoid bogging the reader down with technicalities of the quote reader macro right away, so he provided examples that were very simple but which didn’t actually work when typed as-is into a REPL. At some point somebody thought they should provide working code, but they didn’t want to junk up the original text, so they added the code as a footnote.
The preface says:
Moreover, you may need to modify the programs slightly. Typically, the material requires only a few changes. Suggestions about how to try the programs in the book are provided in the framenotes. Framenotes preceded by "S:" concern Scheme, those by "L:" concern Common Lisp.
Atom just means anything that isn’t a list. As you work through the exercises you’ll need to be able to test an element of a list to see if it is another list. They’re introducing a term for a non-list thing.
Also be aware quoting is handled by the reader, the process of reading and evaluating the expression consumes the quote, so:
(quote atom)
evaluates to
atom
回答2:
Cf. the following interaction in CLISP REPL:
[1]> 'atom
ATOM
ATOM
is the entity to which the text is referring; 'atom
is what the footnote is referring to.
The quoted data handling is one of weaker points about Lisp syntax. There's constant confusion whether what we see is meant as the result of evaluation (ATOM
) or the code ('atom
). Code is data in Lisp, after all, so it blurs the distinction when we do want there to be a distinction.
来源:https://stackoverflow.com/questions/53798845/little-schemer-atom-vs-quote-atom