SICP in Clojure: Chapter 2 (part 1)
Going on with my study of SICP, this is the first part of chapter 2 (that is a very big chapter and also has a lot of great examples). I also updated the code in the first chapter for some issues with chapter 2 names that were replicated (I made some private definitions there to use refer all here). The painter example of this book was really cool and actually you can create a painter with Quil library if you want to see it works. (ns sicp.chapter-2 (:require [sicp.chapter-1 :refer :all])) ;Common functions (defn null? [l] (and (seq? l) (empty? l))) ;Chapther 2: Building Abstractions with Data (defn linear-combination [a b x y] (+ (* a x) (* b y))) (declare add mul) (defn linear-combination [a b x y] (add (mul a x) (mul b y))) ;Chapter 2.1.1 (declare make-rat numer denom) (defn add-rat [x y] (make-rat (+ (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (defn sub-rat [x y] (make-rat (- (* (numer x) (denom y)) ...