From: Ramakrishnan Muthukrishnan Date: Mon, 7 Jun 2010 18:00:52 +0000 (+0530) Subject: solution to 2.4 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/flags//%22%3C?a=commitdiff_plain;h=188e7aa3e2b5398284a4aba1af00589b487da03f;p=sicp.git solution to 2.4 --- diff --git a/src/sicp/ex2_4.clj b/src/sicp/ex2_4.clj new file mode 100644 index 0000000..82f8a2d --- /dev/null +++ b/src/sicp/ex2_4.clj @@ -0,0 +1,19 @@ +(ns sicp.ex2_4 + (:use [sicp utils] + [clojure.test])) + +(defn cons [x y] + (fn [f] (f x y))) + +(defn car [x] + (x (fn [p q] p))) + +(defn cdr [x] + (x (fn [p q] q))) + +;; cons takes x and y and returns a function which takes a param as input +;; which is nother function and calls that function with x and y. Now +;; car of a cons cell, calls this function returned by cons, with another +;; function as input parameter. Remember that cons returns a func which takes +;; another func as input. This function passed takes 2 inputs p and q and +;; returns p in the case of car and q for cdr.