Is lat? a primitive function in Scheme?
Asked Answered
M

2

8

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.

Merridie answered 24/2, 2016 at 20:43 Comment(0)
P
16

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.

Pythagoras answered 24/2, 2016 at 20:54 Comment(1)
Yup. Included the definition in my answer. Thanks for the pointer though.Merridie
M
3

Turns out this is a silly question: the text tasks the reader with devising a definition. Here's the answer in case anyone is interested:

(define lat?
  (lambda (l)
    (cond
      ((null? l) #t)
      ((atom? (car l)) (lat? (cdr l))
      (else #f))))
Merridie answered 24/2, 2016 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.