One of the first questions in the second chapter of The Little Schemer (4th edition) asks the reader to write the function lat?
, where (lat? l)
returns true if l
is a list of atoms.
It goes on to say:
You were not expected to be able to do this yet, because you are still missing some ingredients.
But I'm familiar with recursion, and the definition of atom?
earlier in the book already introduced and
(further implying the existence of or
), so I gave it a shot anyway: (repl)
(define lat?
(lambda (l)
(or
(null? l)
(and
(atom? (car l))
(lat? (cdr l))))))
On the next page, the book introduces the cond
operator to enable this definition of lat?
:
(define lat?
(lambda (l)
(cond
((null? l) #t)
((atom? (car l)) (lat? (cdr l)))
(else #f))))
Is there any significant difference between these two implementations?