Skip to content

Commit

Permalink
introduce KLIPSE in section 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
viebel committed Mar 25, 2016
1 parent 6ae400d commit 7c09582
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions source/section/1.1.7.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,11 @@ always guess that the square root of any number is 1
(sqrt-iter 1.0 x))
```

If we type these definitions to the interpreter, we can use
sqrt just as we can use any function:

```
> (sqrt 9)
3.00009155413138
> (sqrt (+ 100 37))
11.704699917758145
> (sqrt (+ (sqrt 2) (sqrt 3)))
1.7739279023207892
> (square (sqrt 1000))
1000.000369924366
```
Now, let's play with it:
<iframe frameborder="0" width="100%" height="800px"
src=
"http://app.gadjett.com/cljs_compiler/index-dev.html?eval_only=1&cljs_in=(defn%20square%20%5Bx%5D%0A%20%20(*%20x%20x))%0A%0A(defn%20average%20%5Bx%20y%5D%0A%20%20(%2F%20(%2B%20x%20y)%202))%0A%0A(defn%20good-enough%3F%20%5Bguess%20x%5D%0A%20%20(%3C%20(abs%20(-%20(square%20guess)%20x))%200.001))%0A%0A(defn%20improve%20%5Bguess%20x%5D%0A%20%20(average%20guess%20(%2F%20x%20guess)))%0A%0A(defn%20abs%20%5Bn%5D%0A%20%20(max%20n%20(-%20n)))%0A%0A(defn%20sqrt-iter%20%5Bguess%20x%5D%0A%20%20(if%20(good-enough%3F%20guess%20x)%0A%20%20%20%20guess%0A%20%20%20%20(sqrt-iter%20(improve%20guess%20x)%20x)))%0A%0A(defn%20sqrt%20%5Bx%5D%0A%20%20(sqrt-iter%201.0%20x))%0A%0A%5B(sqrt%20100)%0A%20(sqrt%209)%0A%20(sqrt%20(%2B%20100%2037))%0A%20(sqrt%20(%2B%20(sqrt%202)%20(sqrt%203)))%0A%20(square%20(sqrt%201000))%5D">
</iframe>

The sqrt `program` also illustrates that the simple procedural
language we have introduced so far is sufficient for writing any
Expand Down

0 comments on commit 7c09582

Please sign in to comment.