Closed ChengCat closed 5 years ago
Regarding the two new-scope
and namespace
forms, after more thoughts, I think the current design is good. namespace
is for grouping top-level definitions, and can be reentered at a later point; while new-scope
is for introducing a new lexical scope in one of the top-level definitions. They are probably better to be separated as two forms, and it's weird if lexical scopes could be reentered.
As the following code shows, anonymous functions does not have access to structs defined in an outer lexical scope.
I don't completely understand how scoping works with anonymous functions right now, but I think it shouldn't escape from any
new-scope
s, and it should just introduce anew-scope
based on the scope where it's defined. It would still be invalid to reference a local variable from an outer scope, but structs, macros, functions, and possibly others should work fine.It seems to me that
new-scope
shouldn't be handled specially, and could be a library macro.namespace
would then be the only namespace-related core form.For some context, I am working on some utilities for closures:
Then the two macros can be used like this:
Unfortunately this doens't work, because
*Capture*
can not be referenced from inside the anonymous function.