sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit e63ca8e496f7a4e34d88f8ef94574783cb62fa03
parent 7324e84999431c3b6aaf151241696034b7301468
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 25 Jun 2016 18:31:36 +0000

sicp.org: tried ex. 1.9.

Diffstat:
sicp.org | 40++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+), 0 deletions(-)

diff --git a/sicp.org b/sicp.org @@ -107,3 +107,43 @@ For a number as large as 1000000000, guile's =sqrt= function and =sqrt-sicp-alt= returns 31622.776601683792, =sqrt-sicp= returns 31622.776601684047; =sqrt-sicp= being slightly more precise than the other functions. +*** 9 +**** recursive process + +#+BEGIN_SRC scheme +(define (+ a b) + (if (= a 0) + b + (inc (+ dec a) b))) +#+END_SRC + +#+BEGIN_SRC +(+ 4 5) ----+ +(inc (+ 3 5)) |----+ +(inc (inc (+ 2 5))) |------+ +(inc (inc (inc (+ 1 5)))) |------+ +(inc (inc (inc (inc (+ 0 5))))) | +(inc (inc (inc (inc 5)))) +-------+ +(inc (inc (inc 6))) +-----| +(inc (inc 7)) +-----| +(inc 8) +-----| +9 <-----| +#+END_SRC + +**** iterative process + +#+BEGIN_SRC scheme +(define (+ a b) + (if (= a 0) + b + (+ (dec a) (inc b)))) +#+END_SRC + +#+BEGIN_SRC +(+ 4 5 --+ +(+ 3 6) | +(+ 2 7) | +(+ 1 8) | +(+ 0 9) | +9 <------+ +#+END_SRC