Little Schemer atom vs (quote atom)

左心房为你撑大大i 提交于 2020-06-27 16:54:06

问题


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?
  atom1

1(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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!