Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 260
David Shaked Avatar asked Feb 24 '16 20:02

David Shaked


1 Answers

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.

like image 70
Nathan Hughes Avatar answered Nov 09 '22 19:11

Nathan Hughes