Reading: Webster Ch. 10
Here is the example used to show primitive namespaces in Java:
class Reuse {
Reuse Reuse(Reuse Reuse) {
Reuse:
for (;;) {
if (Reuse.Reuse(Reuse) == Reuse)
break Reuse;
}
return Reuse;
}
}
Copy it and then annotate it as follows:
Reuse
that is a definition, describe what binding for Reuse
is establishedReuse
that is not a definition, show which definition is used to bind it.Definition | Binding |
---|---|
class Reuse | Binding for the type Reuse |
method Reuse() | Binding for the method Reuse of type Reuse -> Reuse |
parameter Reuse | Binding for the parameter Reuse of type Reuse in the Method Reuse |
label Reuse: | Binding for the labeled block Reuse |
Use of Reuse | Binding Used |
---|---|
Reuse.Reuse | bound to the method Reuse in the Class Reuse |
(Reuse) | bound to the parameter Reuse of the method Reuse in the class Reuse |
== Reuse | bound to the parameter Reuse of the method Reuse in the class Reuse |
break Reuse | bound to the Label Reuse |
return Reuse | bound to the parameter Reuse of the method Reuse in the class Reuse |
Here is the example used to show the difference between scoping with blocks and dynamic scoping:
fun g x =
let
val inc = 1;
fun f y = y + inc;
fun h z =
let
val inc = 2;
in
f z
end;
in
h x
end;
Copy it and then annotate it as follows:
/--------------------------------------------------------------------------\
| /---------------------------------------------------------\ 0 |
| fun g | x = 1 | |
| /----------/ | |
| | /-------------------------------------------------------------\ | |
| | | let 2 | | |
| | | val inc = 1; | | |
| | | /---------------------\ | | |
| | | fun f | y = y + inc; 3 | | | |
| | | \---------------------/ | | |
| | | /---------------------------------------------\ | | |
| | | fun h | z = 4 | | | |
| | | /----------/ | | | |
| | | | /-------------------------------------------------\ | | | |
| | | | | let 5 | | | | |
| | | | | val inc = 2; | | | | |
| | | | | in | | | | |
| | | | | f z | | | | |
| | | | | end; | | | | |
| | | | \-------------------------------------------------/ | | | |
| | | \--------------------------------------------------------/ | | |
| | | in | | |
| | | h x | | |
| | | end; | | |
| | \-------------------------------------------------------------/ | |
| \--------------------------------------------------------------------/ |
\--------------------------------------------------------------------------/
Definition | Scope | Name | Binding | |
---|---|---|---|---|
g | {0,1,2,3,4,5} |
y in y + inc |
y:{3} |
|
x | {1,2,3,4} |
inc in y + inc |
inc:{2,3,4} |
|
inc | {2,3,4} |
f in f z |
f:{2,3,4,5} |
|
f | {2,3,4,5} |
z in f z |
z:{4,5} |
|
y | {3} |
h in h x |
h:{2,3,4,5} |
|
h | {2,4,5,3} |
x in h x |
x:{1,2,3,4} |
|
z | {4,5} |
|||
inc | {5} |