The first function we look at is
(def rember (fn [ a lat] (cond (null? lat) '() true (cond (= (first lat) a) (rest lat) true (cons (first lat) (rember a (rest lat))))))) (println (rember 'banana '(apple banana orange)))
The big idea here is list construction. We’re applying the second commandment of the Little Lisper – use cons to build lists [sequences].
The next function we look at is
(def firsts (fn [l] (cond (null? l) '() true (cons (first (first l)) (firsts (rest l)))))) (println (firsts '((large burger)(fries coke)(chocolate sundae))))
Here we also meet the Third Commandment of TLS. This states when building a list, describe the typical element, and then cons it onto the natural recursion. This goes back to the discussion on
lat? we were having in the previous chapter. You have to identify the base case, and then build on it.
You can see it working here.