Lexical Scoping - possibly ridiculous idea 
Author Message
 Lexical Scoping - possibly ridiculous idea

The following idea may well be ridiculous so you might want to delete
this message now.

The scoping rules in Pop are interesting, to say the least. Here is a
suggestion on how things could be done differently in some language, not
necessarily Pop. The essence of the idea is that in most languages variables
default to global scope and variabledeclarations limit scope. We could do the
opposite. That is, have default rules defining local scope and have declarations
expand the scope of variables.What follows is a first stab at the default rules.
I am sure this suggestion is notworkable as it stands, but what are news groups
for? :-)

1) All variables default to lexical scope.
   (Pop seems to be drifting this way.)

2) The initial value of a variable is set to the value of the first
   same-named variable in successively less-nested scopes. (That is,
   global import of the initial value is the default.)

3) All varaibles default to having scope of their current lexical block.
   (We would have to tighten up definitions of lexical blocks in Pop.)

4) Default definitions can be over written by explict definitions of
   globality. (See the following examples.)

Example 1
=========

define foo(v1) -> v2; ;;; 1
    for v1 to 10 do   ;;; 2
        ...
    endfor;
    v1 -> v2;         ;;; 3
enddefine;

1) Initial instantiation of variables "v1", "v2";
2) New instance of variable called "v1", shares initial value with "v1"
   at (1).
3) Initial instantiation of "v1" at (1) assigned to "v2".

Example 2
=========

define foo(v1) -> v2; ;;; 1
    lvars v1;         ;;; 2
    for v1 to 10 do   ;;; 3
         ...
    endfor;
    v1 -> v2;
enddefine;

1) Initial instantiation of variables "v1", "v2".
2) Lexically nested versions of "v1" exported to current block.
3) Same computation performed as in Example 1, but with "v1" at (1) not
   "v1" at (2).
4) Value of "v1" after "for" loop assigned to "v2".

Conclusion
==========
An advantage of this proposal for Pop might be that existing code with explicit
variable declarations might be made to work as now, but the absence of variable
declarations brings about tight block-binding of lexical variables. In
other words, "expert" code in the libraries might be unchanged, but code
produced by "novices" would probably fall over. Mind you, most novice code is
ususally short lived, and so are novices! Either they give up or they
become experts. (-: Perhaps there is a third alternative? Let me see. :-)

James Anderson



Sun, 07 Sep 1997 03:24:38 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Lexical scoping good, dynamic scoping bad

2. lexical scoping-please help

3. Lexical Scoping Patch

4. seminar: Providing Modules and Lexical Scoping in Logic Programming

5. Efficient Implementation of Lexical Scoping

6. What's the value of lexical scoping?

7. Yet Another Idea for lexical closures in Python

8. Python 2: Lexical scoping [Re: Python 2 ideas [Re: access fun ctions vs. directly setting attributes]]

9. FW: Python 2: Lexical scoping [Re: Python 2 ideas [Re: access fun ctions vs. directly setting attributes]]

10. A ridiculous problem with MASM

11. Intel give no single tasking mode,ridiculous!

12. ridiculous size of fo

 

 
Powered by phpBB® Forum Software