### Little help about define procedure

Posted:

**Wed Apr 16, 2014 5:50 pm**Hi everybody

I'm trying to study SICP. I use Dr.Racket and intall Neil Van Dyke's SICP Support for DrRacket. When I practice examples of the book, I bumped into something confused me.

The following codes are from the book and I use the procedure "sqrt" at beginning:
It worked perfactly well. But as for my understanding, you have to define a procedure before use it, right? So I don't understand how this can work?

And I do an experiment:
But this time the interpreter gave me "add: undefined; cannot reference undefined identifier", so I am totally confused about these results, can somebody explain what's going to me?

Thank you

I'm trying to study SICP. I use Dr.Racket and intall Neil Van Dyke's SICP Support for DrRacket. When I practice examples of the book, I bumped into something confused me.

The following codes are from the book and I use the procedure "sqrt" at beginning:

Code: Select all

```
(sqrt (+ 100 37))
(define (sqrt-iter guess x)
(if (good-enougth? guess x)
guess
(sqrt-iter (improve guess x)
x)))
(define (improve guess x)
(average guess (/ x guess)))
(define (average x y)
(/ (+ x y) 2))
(define (good-enougth? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (square x)
(* x x))
(define (sqrt x)
(sqrt-iter 1.0 x))
```

And I do an experiment:

Code: Select all

```
(add 2 2)
(define (add x y)
(test x y))
(define (test x y)
(+ x y))
```

Thank you