Why am I getting an unbound error for "atom?"
Asked Answered
S

3

6

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.

Seeto answered 5/6, 2013 at 6:3 Comment(5)
Scheme and Lisp are not the same, and scheme does not have a atom? predicate. However you can easily implement your own: #5405207Rapport
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 :-)Seeto
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.Rapport
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.Skewbald
@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.Erbes
P
5

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.

Pondweed answered 5/6, 2013 at 17:11 Comment(2)
I have a PDF of the third edition. My mistake was skipping through the preface, which clearly mentioned that the atom function needed to be defined. Plus, I compounded that error by trying run Lisp commands on a Scheme editor, and not fully comprehending the differences between the two. I'll stick to SBCL with Emacs.Seeto
@Tavore, I wouldn't use SBCL with The Little Lisper. The Little Lisper used Scheme, not Common Lisp, even when it was called "The Little Lisper" rather than "The Little Schemer". (And as you've found, it defines atom? in the preface.) Footnotes tell you how to do the same things in CL, but it's easier to use Scheme--especially if you get into the later material on the Y combinator.Sexcentenary
M
2

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.

Midbrain answered 5/6, 2013 at 13:41 Comment(2)
I do have SICP. I was planning to go through it after I finished the Little Lisper. I also have the Little Schemer, which I am yet to read. I've been stockpiling the books and getting confused between them. Thanks.Seeto
SICP and The Little Lisper/Schemer have very different costs and benefits. Going through TLL/S before SICP could be a very good idea.Sexcentenary
T
1

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.

Terceira answered 5/6, 2013 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.