3

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.

Community
  • 1
  • 1
yroc
  • 886
  • 1
  • 10
  • 16

2 Answers2

6

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
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • 1
    Thank you. But why does `atom` need to be quoted whereas subsequent examples of atoms (e.g., `turkey`, `1492`) don't? – yroc Dec 16 '18 at 15:06
  • 1
    @yroc they need to be quoted too. The book uses special font for code snippets which are meant to be quoted if entered at the REPL. (IIRC). (1492, being a number - a self-evaluating entity - needs not be quoted) – Will Ness Dec 16 '18 at 15:42
  • @yroc: 1492 doesn't have to be quoted because it evaluates to itself. – Nathan Hughes Jan 02 '19 at 19:41
  • Not explaining something is an odd way "to avoid bogging the reader down." I'd guess that quite a lot of people are discouraged by the fact that you can't work through these initial questions in a Scheme REPL. You're immediately thrown into wondering what quoting means. Having typed `'atom` and `1492` into ones REPL (and finding that they evaluate to a symbol and an integer respectively), one then tries entering the `(atom)` example as `('atom)` and gets, instead of a list, an error about procedures and is left wondering why it's `'(atom)`, as given in the framenote. – George Hawkins May 11 '20 at 10:45
  • This leads you to SO answers like this one on [`list` vs `quote`](https://stackoverflow.com/questions/34984552/what-is-the-difference-between-quote-and-list). This doesn't really seem the gentle introduction, I'd expected. Sorry @NathanHughes - I know you're not the book's author, but you're the only person I could find who tries to address why the authors took this approach. I get the constructivist/dialog thing but I think a blog post on how to approach this book (and getting started with it with something real like Racket) would be a great help for many. – George Hawkins May 11 '20 at 10:47
  • The book says re: `1492` being an atom: "Yes, because `1492` is a string of digits." So it's unclear whether the author meant `1492` or `'1492`? – joseville Dec 11 '21 at 18:36
  • 1
    @joseville: I think they meant to point out that numbers are atoms the same way strings are atoms. – Nathan Hughes Dec 11 '21 at 19:58
1

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.

Will Ness
  • 70,110
  • 9
  • 98
  • 181