Add exercise 3.8
This commit is contained in:
parent
3d8bad6a34
commit
91d3bafd2c
|
@ -0,0 +1,24 @@
|
|||
#lang sicp
|
||||
|
||||
(define f
|
||||
(let ((x 0))
|
||||
(lambda (n)
|
||||
(let ((old-x x))
|
||||
(begin
|
||||
(set! x n)
|
||||
(cond ((= n 0)
|
||||
(if (= old-x 0) -1 0))
|
||||
(else n)))))))
|
||||
|
||||
(define left-to-right
|
||||
(let ((left (f 0))
|
||||
(right (f 1)))
|
||||
(+ left right)))
|
||||
|
||||
(define right-to-left
|
||||
(let ((right (f 1))
|
||||
(left (f 0)))
|
||||
(+ left right)))
|
||||
|
||||
;; (f 0) first: (+ (f 0) (f 1)) -> 0
|
||||
;; (f 1) first: (+ (f 0) (f 1)) -> 1
|
Loading…
Reference in New Issue