From: Andrew Parker <[EMAIL PROTECTED]>
   Date: Tue, 12 Feb 2008 15:17:03 +0100

   Thanks for the pointer, Bob.  I read through it and it might be  
   tangentially related to this.  That problem is about scopes being  
   modeled by subs in parrot.  IMHO there is not a great problem there,  
   since a sub is really an abstraction for entering and leaving a scope  
   and so a good abstraction for what is being done.  

I tend to disagree.  I think of subs as equivalent to HLL procedures.
When the compiler has to split the user's expression of the problem into
multiple subs, that can only make it harder to debug.  But I've already
been overruled on this, and don't want to reopen the issue.

   Gotos can and are a problem then, but I'm not sure what the semantics
   are for jumping into a scope via a goto in any language is.

You can jump into scopes in Perl 5, though I doubt the semantics are
well-defined.  ISTR that, while playing around with the RT#44395
test-closures-4.pl attachment before posting, I got Perl to jump over
the variable inits; printing the variables showed their previous value.
But this has an "implementation artifact" sort of smell, and is
borderline pathological in any case.

   And jumping into variable scopes is not possible at all in Common
Lisp, where any such jump targets would be out of scope.  I expect most
lexically-scoped languages with "goto" are like this, but I don't have
experience with any others myself.

   My problem is that once you get into the new scope the vars of the  
   outer scope don't seem to be accessible if the new scope has a var  
   that shadows (creates a new var with the same name).

   . . .

   Thinking about it right now it could be done by passing the required  
   vars into the inner scope's sub as parameters.  I'd have to think  
   about that some more to make sure it would cover all of the required  
   cases, but my hunch right now is that it won't (or will take a lot of  
   hoop jumping).

   Andrew Parker

I believe it would work for all cases.  Recall that "let" in Lisp
dialects is equivalent to calling a constant lambda:

        (let ((x 1)) (+ x 1)) => ((lambda (x) (+ x 1)) 1)

If you were to perform this transformation before lexical analysis and
then resist the temptation to inline the lambda, that might get you what
you need without too much trouble.  Good luck, though.

                                        -- Bob

Reply via email to