I'm reading the 10th chapter of the book "The little schemer - 4th edition", which implements a simple schemer interpreter. All the other content is fine to me, except the function :atom? in Page 188:
(define :atom?
(lambda (x)
(cond
((atom? x) #t)
((null? x) #f)
((eq? (car x) (quote primitive)) #t)
((eq? (car x) (quote non-primitive) #t)
(else #f)))))
I'm not clear about this line:
((eq? (car x) (quote non-primitive) #t)
From the previous of the book, the non-primitive is corresponding to a lambda definition.
(lambda (x) (+ x 1))
has the value of (with the passing environment table):
(non-primitive (table (x) (+ x 1)))
Does this mean a lambda definition is an atom, in the book?
I guess it is but not quite sure about it since I can't find their relationship mentioned in the book.
Source code
(lambda (x) (+ x 1))would not be an atom, but the evaluated value which results in a closure should be identified by the evaluator as an atom.In lisps everything that is not a a list is an atom. You could define it like this:
Now if you modeled your closures as
pairswith first element as a tag identifying it as such you need to make sure those evaluates as atomic too and that's what your:atom?does by looking forprimitiveandnon-primitive