Does anyone know when lexical scope started appearing in Lisp? Not
counting Scheme, did it exist in predecessors of Common Lisp? Was it
used much? Is it really true that Common Lisp had both lexical and
dynamic scope in order to support older code that was written relying on dynamic scope and was too hard to convert?
Thanks. This topic came up in the Forth group.
On Fri, 15 Mar 2024 16:05:37 -0600, Jeff Barnett wrote:
Once you have had the programming convenience of using dynamic scope,
you would miss it terribly in a lexical-only language, or worse, in
something like the old FORTRAN assembler-level scope. Another argument
that I have not seen debated but may be significant is that the CL Error
System -- the programming primitives and error class structures don't
make a lot of sense in lexical only. The error mechanisms like catch
have meanings that include phrases such as "while executing this. I'm
available to handle that".
Lexical binding has always been understood to apply to references to definitions of identifiers. Exception handlers are dynamically-installed (lexical-based exception handling doesn’t make any sense), nevertheless
the names of the defined exceptions being handled are still lexically-
bound.
This is how it works in every rationally-designed language.
Once you have had the programming convenience of using dynamic scope,
you would miss it terribly in a lexical-only language, or worse, in
something like the old FORTRAN assembler-level scope. Another argument
that I have not seen debated but may be significant is that the CL Error System -- the programming primitives and error class structures don't
make a lot of sense in lexical only. The error mechanisms like catch
have meanings that include phrases such as "while executing this. I'm available to handle that".
For instance, the Guice dependency injection framework
for Java implements @RequestScoped settings, which are dynamically
scoped and thread local.
Guice wouldn't need that feature if Java
natively supported dynamically-scoped variables.
Does anyone know when lexical scope started appearing in Lisp? Not
counting Scheme, did it exist in predecessors of Common Lisp? Was it
used much? Is it really true that Common Lisp had both lexical and
dynamic scope in order to support older code that was written relying on dynamic scope and was too hard to convert?
First off, I believe that many if not most exception-related primitives expand in terms of dynamic variables.
On 3/15/2024 4:26 PM, Lawrence D'Oliveiro wrote:
On Fri, 15 Mar 2024 16:05:37 -0600, Jeff Barnett wrote:
Once you have had the programming convenience of using dynamic scope,
you would miss it terribly in a lexical-only language, or worse, in
something like the old FORTRAN assembler-level scope. Another argument
that I have not seen debated but may be significant is that the CL Error >>> System -- the programming primitives and error class structures don't
make a lot of sense in lexical only. The error mechanisms like catch
have meanings that include phrases such as "while executing this. I'm
available to handle that".
Lexical binding has always been understood to apply to references to
definitions of identifiers. Exception handlers are dynamically-installed
(lexical-based exception handling doesn’t make any sense), nevertheless
the names of the defined exceptions being handled are still lexically-
bound.
This is how it works in every rationally-designed language.
First off, I believe that many if not most exception-related primitives expand in terms of dynamic variables. And second, it would be amusing to unwind to an environment that is lexically alive but execution dead-
think about restarting the contexts that were abandoned.
(block foo (unwind-protect (sys:abscond-from foo 42) (prinl 'unwind)))42
(block foo (unwind-protect (return-from foo 42) (prinl 'notprinted)))notprinted
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Fri, 15 Mar 2024 20:23:51 -0400, Robert Brown wrote:
For instance, the Guice dependency injection framework for Java
implements @RequestScoped settings, which are dynamically scoped and
thread local.
Can’t find any mention of “dynamic” scoping in the docs
<https://github.com/google/guice/wiki/Scopes>. “@RequestScoped” just
seems to mean what it says: the scope is per-request.
The use of thread local state to store request scoped Guice bindings is discussed in this thread:
https://groups.google.com/g/google-guice/c/gDonVGO1wjY/m/_SSi4CcQAJYJ
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.
However if your point is that you can build "simulations" of one sort of scoping out of primitives for another sort ...
Does anyone know when lexical scope started appearing in Lisp? Not
counting Scheme, did it exist in predecessors of Common Lisp? Was it
used much? Is it really true that Common Lisp had both lexical and
dynamic scope in order to support older code that was written relying
on dynamic scope and was too hard to convert?
Dynamic scope is necessary for some things (e.g. mutable global
variables, the condition system, thread-local storage, etc.) ...
Just think of the following when specifying a variable's intent: is it supposed to influence an evaluation or is it supposed to influence an evaluation when it's in a particular lexical scope? Does that help you
any?
The example of error handling is that it's generally supposed to control
an evaluation. If error handling was lexically based ...
On Sat, 16 Mar 2024 23:13:20 -0600, Jeff Barnett wrote:
However if your point is that you can build "simulations" of one sort of
scoping out of primitives for another sort ...
No, my point was that there seems to be no need for dynamic scoping, if
the only excuse anyone can come up for needing it comes out of exception handling.
second ALGOL spec on the requirements for OWN variables: if the spec was
--
Jeff Barnett
ALGOL60 is an early experiment.
In article <ut7rkt$3p750$1@dont-email.me>,
Jeff Barnett <jbb@notatt.com> wrote:
second ALGOL spec on the requirements for OWN variables: if the spec was
You can't refer to ALGOL like this. It is either ALGOL60 or ALGOL68.
These are totally different languages.
ALGOL60 is an early experiment. ALGOL68 is practically Google's go.
... you really can't escape from one dynamic scope to
another.
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.
Does anyone know when lexical scope started appearing in Lisp?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 405 |
Nodes: | 16 (2 / 14) |
Uptime: | 76:43:59 |
Calls: | 8,510 |
Calls today: | 11 |
Files: | 13,206 |
Messages: | 5,919,673 |
Posted today: | 1 |