# SICP 第１章の要点を簡単にまとめてみた 〜『プログラムは魔法と似ている』〜

#### Chapter 1 Building Abstractions with Procedures

（抽象化を構築するやり方）

The programs we use to conjure processes are like a sorcerer's spells.

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-9.html#%_chap_1

（一連の処理を呼び出すプログラムは、魔術師の呪文と似ている。）
== プログラムは魔法と似ている

##### 1.1 The Elements of Programming

primitive expressions, which represent the simplest entities the language is concerned with,

means of combination, by which compound elements are built from simpler ones, and

means of abstraction, by which compound elements can be named and manipulated as units.

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1

#### 1.2 Procedures and the Processes They Generate

##### 1.2.1 Linear Recursion and Iteration

recursive process（再帰処理）

```(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
```

iterative proces（反復処理）

```(define (factorial n)
(fact-iter 1 1 n))

(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
```

#### 1.3 Formulating Abstractions with Higher-Order Procedures

##### 1.3.2 Constructing Procedures Using Lambda

（ラムダを使うやり方）

```     (lambda             (x)             (+    x     4))
;        ^                ^               ^    ^     ^
; the procedure   of an argument x  that adds  x and 4
(define (pi-sum a b)
(sum (lambda (x) (/ 1.0 (* x (+ x 2))))
a
(lambda (x) (+ x 4))
b))
```

Using let to create local variables（let を使ってローカル変数を作り出す）

```(define (f x y)
(let ((a (+ 1 (* x y)))
(b (- 1 y)))
(+ (* x (square a))
(* y b)
(* a b))))
```