Sujet : Re: History of lexical scope in Lisp
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.lispDate : 16. Mar 2024, 09:27:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ut3hlt$2pi20$1@dont-email.me>
References : 1 2 3 4
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Sat, 16 Mar 2024 00:46:21 -0600, Jeff Barnett wrote:
First off, I believe that many if not most exception-related primitives
expand in terms of dynamic variables.
Consider the following Python example:
class MyException1(Exception) :
pass
#end MyException1
class MyException2(Exception) :
pass
#end MyException2
def func1() :
raise MyException1
#end func1
def func2() :
raise MyException2
#end func2
def func3() :
class MyException1(Exception) :
pass
#end MyException1
try :
func1()
except MyException1 :
# will never get here
print("caught MyException1 in func3")
#end try
#end func3
def func4() :
try :
func2()
except MyException2 :
print("caught MyException2 in func4")
#end try
#end func4
for f in (func1, func2, func3, func4) :
try :
print("* call %s" % f.__name__)
f()
except MyException1 :
print("caught MyException1 at top level")
except MyException2 :
print("caught MyException2 at top level")
#end try
#end for
Here is the output it produces:
* call func1
caught MyException1 at top level
* call func2
caught MyException2 at top level
* call func3
caught MyException1 at top level
* call func4
caught MyException2 in func4
func4 shows how the search for a handler is based on dynamic execution
nesting. func3 shows how exception matching is based on lexical
scoping.