Email or username:

Password:

Forgot your password?
Gosha

That child-like delight when I figured out #SICP exercise 1.6, haha. I love this very much.

Exercise 1.6: Alyssa P. Hacker doesn’t see why `if` needs to be provided as a special form. “Why can’t I just define it as an ordinary procedure in terms of `cond`?” she asks. Alyssa’s friend Eva Lu Ator claims this can indeed be done, and she defines a new version of if:
```
(define (new-if predicate then-clause else-clause)
(cond (predicate then-clause)
(else else-clause)))
```

Eva demonstrates the program for Alyssa:
```
(new-if (= 2 3) 0 5)
5
(new-if (= 1 1) 0 5)
0
```

Delighted, Alyssa uses new-if to rewrite the square-root program:
```
(define (sqrt-iter guess x)
(new-if (good-enough? guess x)
guess
(sqrt-iter (improve guess x) x)))
```

What happens when Alyssa attempts to use this to compute square roots? Explain.
5 comments
フェリ―ペ

@gosha it's so good isn't it?! im stuck on exercise 1.11 for now

Alastair M. D. Touw

@gosha I love the little epiphanies that stay with you forever, but… Eva Lu Ator? 👏🏻😒

Gosha

@amdt A member of @neauoire‘s extended family? 🤔

Devine Lu Linvega

@gosha @amdt It's the name I use during halloween on the instance.

Kototama

@gosha you can do that in Haskell because it's lazy evaluated :blob_cat_peek:

Go Up