1

It might be frivolous, but I are not aware where to ask the question.

I am reading SICP and very confused about its description about a dummy simple concept of scope : Local Name

This principle -- that the meaning of a procedure should be independent of the parameter names used by its author -- seems on the surface to be self-evident, but its consequences are profound. The simplest consequence is that the parameter names of a procedure must be local to the body of the procedure. For example, we used square in the definition of good-enough? in our square-root procedure:

(define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001))

The intention of the author of good-enough? is to determine if the square of the first argument is within a given tolerance of the second argument. We see that the author of good-enough? used the name guess to refer to the first argument and x to refer to the second argument. The argument of square is guess. If the author of square used x (as above) to refer to that argument, we see that the x in good-enough? must be a different x than the one in square. Running the procedure square must not affect the value of x that is used by good-enough?, because that value of x may be needed by good-enough? after square is done computing.

I am stuck with

If the author of square used x (as above) to refer to that argument, we see that the x in good-enough? must be a different x than the one in square. Running the procedure square must not affect the value of x that is used by good-enough?, because that value of x may be needed by good-enough? after square is done computing.

What's 'that argument' refer to?

Did the author said switching x and guess?

2
  • 1
    "The argument of square is guess. If the author of square used x (as above) to refer to that argument, ... " Commented Oct 26, 2019 at 15:39
  • thank you very much, I got it, but it's not a good illustration, cos, guess and x are initially get passed from good-enough? just from the second interation, guess in square will not be affetctd since it is re-assigned.. confused with author to explain it in this way.. @MichaelHarvey
    – Wizard
    Commented Oct 26, 2019 at 16:41

1 Answer 1

1

"That argument" is guess, i.e. the first (and only) argument passed to square.

If you're wondering if there is a rule to help you determine, on the basis of grammar alone, what that refers to, the answer is no. Often the referent of that is grammatically ambiguous, so you must sort it out according to what makes the most sense in the context.

The context here is the use of the name x to refer to different things in different places in the program. If you typed the following into Scheme:

(define (square x) (* x x))

(define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001))

(good-enough? 2.01 4)

then, while the last line was being evaluated, x would refer to 2.01 inside square and x would refer to 4 inside good-enough?.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .