[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jan 20 14:46:04 1993 
Subject:Re: lvars and standards (was: Re: List and Vector Syntax) 
From:Brian Harvey 
Volume-ID:930121.05 

sfk@otter.hpl.hp.com (Steve Knight) writes:
>> Procedure A, with local variable LA, invokes B, with local variable LB.
>> An error occurs inside B.  We are now in a break loop.  In what environment
>> are we working?  With lexical scope I can see three possible answers:
>
>> 2.  We're in B's environment.  Now LB is available in the ordinary way,
>> but LA still isn't.
>
>This is where Brian departs from the usual view of lexical binding.
>Inside B's environment, LA is certainly visible.  Whether B makes
>no reference (or makes a reference) to LA has no effect on scoping.

Now I'm really confused.  If B isn't lexically within A, then LA is *not*
visible.  I'm thinking about an example like this.  (Not beng a Pop programmer,
I'll have to use another language, sorry...)  You've written some general
utility procedure, such as

(define (nth num lst)
  (if (= n 0)
      (car lst)
      (nth (- num 1) (cdr lst)) ))

Now you use that [correct] procedure in writing another one:

(define (last sequence)
  (let ((size (length sequence)))
    (nth size sequence) ))           ; error

Here you have forgotten that nth counts from zero, so the last element
is number SIZE-1, not number SIZE.  You try running the program and it
blows up, attempting to apply CDR to an empty list.  The error is caught
in NTH, but the error is really in LAST.

Since NTH is not lexically within LAST, at the moment when the error
is caught the variable SIZE is not visible; it's in the wrong scope.
And that's the variable you have to examine to figure out what went
wrong.

What am I missing here?