https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/index.htm

https://github.com/DeathKing/Learning-SICP

https://mitpress.mit.edu/sites/default/files/sicp/index.html

https://www.bilibili.com/video/BV1Xx41117tr?from=search&seid=14983483066585274454

https://mitpress.mit.edu/sites/default/files/sicp/psets/index.html

# 1. Procedure Types and Procedure Constructors

## Exercise 1.A

(define (thrice f)
(compose (compose f f) f))

((thrice thrice) f)
((compose (compose thrice thrice) thrice)) f)
((compose (lambda (x) (thrice (thrice x))) thrice)) f)
((lambda (x) ((lambda (x) (thrice (thrice x))) (thrice x))) f)

(repeated f 27)

(((thrice thrice) 1+) 6)

6 + 27 = 33

(((thrice thrice) identity) compose)

identity是恒等映射，所以最后的结果为compose。

(((thrice thrice) square) a)

(((thrice thrice) square) 1)

(((thrice thrice) square) 2)

## Exercise 1.B

(load "utils.scm")

(((thrice thrice) 1+) 6)

(((thrice thrice) identity) compose)

(((thrice thrice) square) 1)

; 数字太大导致溢出
; (((thrice thrice) square) 2)

1 ]=> (((thrice thrice) 1+) 6)
;Value: 33

1 ]=> (((thrice thrice) identity) compose)
;Value 13: #[compound-procedure 13 compose]

1 ]=> (((thrice thrice) square) 1)
;Value: 1

1 ]=> ; 数字太大导致溢出
; (((thrice thrice) square) 2)

# 2. Curves as Procedures and Data

## Exercise 2

### 2

(load "curves.scm")

(define (vertical-line point length)
(lambda (t)
(make-point
(x-of point)
(+ (y-of point) (* t length)))))

## Exercise 3

(load "curves.scm")

(define (reflect-through-y-axis curve)
(lambda (t)
(let ((ct (curve t)))
(make-point
(- (x-of ct))
(y-of ct)))))

## Exercise 4

https://github.com/AyberkSorgun/Project2-Graphing-with-Higher-Order-Procedures/blob/master/project2.scm

(load "curves.scm")

(define (connect-ends curve1 curve2)
(connect-rigidly
curve1
((translate (- (x-of (curve1 1)) (x-of (curve1 0)))
(- (y-of (curve1 1)) (y-of (curve1 0)))) curve2)))