learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-9.scm (845B)


      1 (define-library (sicp solutions chapter-1 exercise-9)
      2   (import (scheme base))
      3   (export inc
      4           dec
      5           first-+
      6           second-+)
      7 
      8   (begin
      9     (define (inc x) (+ x 1))
     10     (define (dec x) (- x 1))
     11 
     12     #!
     13 
     14     *Exercise 1.9:* Each of the following two procedures defines a
     15     method for adding two positive integers in terms of the procedures
     16     `inc', which increments its argument by 1, and `dec', which
     17     decrements its argument by 1.
     18 
     19     !#
     20 
     21     (define (first-+ a b)
     22       (if (= a 0)
     23           b
     24           (inc (first-+ (dec a) b))))
     25 
     26     (define (second-+ a b)
     27       (if (= a 0)
     28           b
     29           (second-+ (dec a) (inc b))))
     30 
     31     #!
     32 
     33     Using the substitution model, illustrate the process generated by
     34     each procedure in evaluating `(+ 4 5)'.  Are these processes
     35     iterative or recursive?
     36 
     37     !#
     38     ))