Question

I'm trying to go through "The Little Lisper" and already running into snags in the first chapter. I'm relatively new to Emacs (which has fueled my interest in learning Lisp and clojure). I downloaded the Mit-scheme app, and am working the exercises on Edwin.

I'm trying:

(atom? (cons a l))

where a is an atom and l is a list already defined. I get the following error:

;Unbound variable: atom?

Why? I have no problems using the "null?" function. I thought "atom?" is an internal function checking to see if the value returned is an atom.

Any explanation would be much appreciated. I still haven't set up my emacs to run scheme, and the minor differences between all the lisp dialects is testing my patience.

Was it helpful?

Solution

In "The Little Schemer" ("The Little Lisper"'s updated version) the atom? procedure is defined as follows (because atom? doesn't exist in Scheme):

(define (atom? x)
  (and (not (null? x))
       (not (pair? x))))

If you're following an old version of the book, I advise you to either look for a newer version or use the same programming language used in the book: Common Lisp for The Little Lisper, Scheme for The Little Schemer - and Racket is a great Scheme IDE to work with! take a look at this answer for some tips when going through The Little Schemer using Racket.

OTHER TIPS

I'm trying to go through "The Little Lisper"... I downloaded the Mit-scheme

Common Lisp and Scheme are very different languages.

You have to either use a different book (e.g., SICP) to match your language implementation or a different language implementation (e.g., clisp or sbcl) to match your book.

Take a look at the Scheme R5RS specification; it includes a list of functions and syntactic keywords. Although not part of the Scheme standard, mit-scheme has a function apropos that will find functions (other stuff) with a given name. try:

(apropos "atom")

(but it won't show anything, :-).

An atom is something that is not a 'cons cell' (generally, if I remember my CommonLisp). In Scheme you could implement one as:

(define (atom? thing) (not (pair? thing)))

Note: this definition of atom? is consistent with CommonLisp atom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top