Sujet : Re: History of lexical scope in Lisp
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.lispDate : 19. Mar 2024, 07:44:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <utb8on$lttb$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Mon, 18 Mar 2024 23:02:23 -0600, Jeff Barnett wrote:
... you really can't escape from one dynamic scope to
another.
Au contraire, with dynamic scoping, such “escaping” happens all the time.
Here’s an example from a language, namely Perl, which does allow for
dynamic scoping (in fact, early on it had no lexical scoping):
$a = 1;
sub f1()
{
$a = $a + 1;
} # f1
sub f2()
{
local $a = 3;
print "inner ", $a, "\n";
f1();
print "inner ", $a, "\n";
} # f2
f1();
print "outer ", $a, "\n";
f2();
print "outer ", $a, "\n";
f1();
print "outer ", $a, "\n";
The output is
outer 2
inner 3
inner 4
outer 2
outer 3
I didn’t say error handling was lexically based, I said the matching of
exceptions was lexically based. I thought my example made that
distinction clear.
Maybe it did but not to me.
Look back again, and see how the outer exception is not the same as the
one with the same name local to the function, yet the catch clauses search
for the exceptions according to dynamic execution nesting.
Want me to go over it step-by-step?