[racket] Little Schemer, lat?

From: Frank Weytjens (fweytjens.android at gmail.com)
Date: Fri Jan 2 17:58:23 EST 2015

Happy new year Racketeers,

The Little Schemer is my favorite book.
I have a kind of Sisyphus relationship with it.
In the preface they advice to not read it, in less then 3 times.
The jokers! It's more then 3 years I read this book, from time to time.
Hoping to get further and further, each time.
I enjoy to start over and over, without completely understanding it.
Like if: once it 's completely understood, there is no more interesting
stuff on earth.
This time i got stuck much earlier, then normal, extremely early.

(define lat?
    (lambda (l)
      (cond
            ((null? l) #t)
            ((atom? (car l)) (lat? (cdr l)))
            (else #f))))

An empty list is a list, but is it a lat ?
If you give an empty list as argument to the lat?-function, the answer is
yes. But an atom must be a string of characters or numbers, or even one
character, or a combination of special characters as long as it is not an (
or an ). The empty list contains no characters at all, so it can not be a
list of atoms. It would be OK, if you recur at least once. But when you
feed an empty list, this is not the case. Then the answer of (null? l)
should be #f

Rewriting the function that way, would never give #t as answer

(define lat?
    (lambda (l)
      (cond
            ((null? l) #f)
            ((atom? (car l)) (lat? (cdr l)))
            (else #f))))


So an empty list has to be a lat, and it is not.
Or is it? Then an empty list can be anything.


Thanks,

Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150102/6e530b04/attachment-0001.html>

Posted on the users mailing list.