]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_4.clj
Lazy version of evaluator and tests.
[sicp.git] / src / sicp / ex2_4.clj
1 (ns sicp.ex2_4
2   (:use [sicp utils]
3         [clojure.test]))
4
5 (defn cons [x y]
6   (fn [f] (f x y)))
7
8 (defn car [x]
9   (x (fn [p q] p)))
10
11 (defn cdr [x]
12   (x (fn [p q] q)))
13
14 ;; cons takes x and y and returns a function which takes a param as input
15 ;; which is nother function and calls that function with x and y. Now
16 ;; car of a cons cell, calls this function returned by cons, with another
17 ;; function as input parameter. Remember that cons returns a func which takes
18 ;; another func as input. This function passed takes 2 inputs p and q and
19 ;; returns p in the case of car and q for cdr.