Search code examples
schemethe-little-schemer

Is lat? a primitive function in Scheme?


Suppose l is defined as follows:

> (define l (list 1 2 3))

l is now bound to a list of atoms.

Little Schemer introduces a simple function called lat? which evaluates to #t or #f depending on the argument's classification as a list of atoms. For instance,

> (lat? l)

should evaluate to #t, since l is a list of three atoms.

However, my scheme interpreter (repl.it) throws an error when asked to call lat?.

> (lat? l)
Error: execute: unbound symbol: "lat" []

Am I wrong in assuming lat? is primitive to Scheme?

Also, please excuse a repost be that the case.


Solution

  • lat? is defined early on in the book. See page 19.

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

    The book specifies what a function needs to do and what outputs it needs to generate in a conversational way that may take getting used to.