Last active
September 1, 2019 01:35
-
-
Save disposedtrolley/b9b60cc983ce5e9ba4ab9ce6043a7963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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