[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lexical scoping



I wrote a solution in T to Ellis's BIT-SET:RANGE:CHOOSE problem but
was unable to use the structure I wanted because of T's name-scoping
rules.  Here's the skeleton of what I wanted to do:
    
(DEFINE (BIT-SET:RANGE:CHOOSE SET LOW HIGH)
  (LABELS ((SCAN (LAMBDA (SET BASE PHASE)
             (LABELS (
   
                (PH1 (LAMBDA (CONT)  
                     ... SET ... BASE ...
                     ... (CONT PH1) ...
                     ... (CONT PH2) ... ))
               
                (PH2 (LAMBDA (CONT)  
                     ... SET ... BASE ...
                     ... (CONT PH2) ... )))
               
              (... (PHASE (LAMBDA (NEXT-PHASE)
                     (SCAN NEW-SET NEW-BASE NEXT-PHASE))) ... )))))
   
           (... (SCAN SET 0 PH1) ... )))

Thus, PHASE is bound to either PH1 or PH2 and so acts as a switch.
The problem of course is that PH1 is unbound in the last line.  However,
pulling the definitions of PH1 and PH2 out of SCAN does not work since
then the references to SET and BASE which they contain become unbound.
What is the solution, other than pulling them out and then passing
SET and BASE as explicit arguments?

--Mike