]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_28.clj
Lazy version of evaluator and tests.
[sicp.git] / src / sicp / ex2_28.clj
1 (ns sicp.ex2_28
2   (:use [clojure.test]))
3
4 ;; take a list of nested lists and return a flat list with elements
5 ;; in the same left-to-right order
6 (defn fringe [lst]
7   (cond (not (seq? lst)) (list lst)
8         (empty? lst)     nil
9         :else (concat (fringe (first lst))
10                       (fringe (rest lst)))))
11
12 (deftest test-fringe-with-simple-list
13   (is (= (fringe '(1 2 3 4)) '(1 2 3 4))))
14
15 (deftest test-fringe-with-nested-list
16   (are [x y] [= x y]
17        (fringe '((1 2) 3 4))   '(1 2 3 4)
18        (fringe '(1 2 (3 4)))   '(1 2 3 4)
19        (fringe '((1 2) (3 4))) '(1 2 3 4)))