5
votes

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.

3
Scheme and Lisp are not the same, and scheme does not have a atom? predicate. However you can easily implement your own: stackoverflow.com/questions/5404707/…Anders Lindahl
I did see that thread, but I think I did not understand it correctly. I understand my mistake is that I'm trying to work these exercises in "Edwin" which runs in scheme mode. Can you tell me of any other application where I can try and work the examples for "The Little Lisper"? Should I try sbcl on emacs? Still working my way through where define/defun/defn fits :-)Tavore
You could try clisp, but you could also switch to a scheme book. The complete text to the classical Structure and interpretation of computer programs is freely available.Anders Lindahl
atom? is not a function in Common Lisp (which clisp implements). In fact, in Common Lisp predicates are typically named with a "p" suffix, so the name atom? does suggest Scheme.Elias Mårtenson
@AndersLindahl Lisp is actually a little ambiguous today, but not in the 70s when The little Lisper came out. The R1RS from 1978 run on MacLisp and used both implementation and name from the primitives. Thus atom, eq, and null are R1RS primitives. In R2RS they started with the question marks and that is kind of a tell tale difference between Scheme and Common Lisp from there on. The SICP videoes say they teach you Lisp but it really is R3RS.Sylwester

3 Answers

4
votes

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.

2
votes

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.

1
votes

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.