Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Last active October 16, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/e8c4e9ba703b19f2cc96224bc073d60a to your computer and use it in GitHub Desktop.
Save lazywithclass/e8c4e9ba703b19f2cc96224bc073d60a to your computer and use it in GitHub Desktop.
Exercises after The Little Schemer chapter 1
;; given leq? that checks for lists equality
;; complete the following, so that the result is true
;; all these exercises can be solved with combinations of
;; car, cdr, cons
;; be creative!
;; this is just an example I solved for you :)
;; l -> (1 2 3)
;; m -> (0 1 2 3)
(leq? l (cdr m))
;; l -> (a b c)
;; m -> (42 a b c)
(leq? l m)
;; l -> (a b 42 c)
;; m -> (a b c)
(leq? l m)
;; l -> (a b c)
;; m -> (b c)
(leq? l m)
;; l -> (a b c)
;; m -> (((a b c)))
(leq? l m)
;; l -> (c b a)
;; m -> (a)
(leq? l m)
;; BONUS! solve also these two and I won't ask a cake next time!
;; given l -> (b ((c)) a)
;; and having only car at your disposal
;; make it so that the following is true
(atom? l)
;; given l -> ()
;; and having only cons at your disposal
;; make it so that the following is true
(leq? (cdr l) (b c (a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment