Skip to content

Instantly share code, notes, and snippets.

@disposedtrolley
Last active September 1, 2019 01:35
Show Gist options
  • Save disposedtrolley/b9b60cc983ce5e9ba4ab9ce6043a7963 to your computer and use it in GitHub Desktop.
Save disposedtrolley/b9b60cc983ce5e9ba4ab9ce6043a7963 to your computer and use it in GitHub Desktop.
;; Bits and pieces from reading The Little Schemer, implemented in Racket.
#lang racket
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
;; Returns whether the supplied s-expression is a list of atoms by
;; recursively checking each element of the input.
(define (lat? l)
(cond
;; Base case -- we've reached the end of the expression.
[(null? l) #t]
;; Break down the problem into smaller and smaller subsets of the
;; original expression.
[(atom? (car l)) (lat? (cdr l))]
;; Short-circuit if we encounter an expression which is not an atom.
[else #f]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment