[Python-ideas] Modern language design survey for "assign and compare" statements
Tim Peters
tim.peters at gmail.com
Sun May 20 19:49:22 EDT 2018
[Tim, on Rebol/Red]
>> >> x: 12 y: 13
>> == 13
>> >> [x y]
>> == [x y]
>> >>
>> >> do [x y]
>> == 13
[Greg Ewing <greg.ewing at canterbury.ac.nz>]
> How does scoping work? If you pass a block to a function
> which evaluates it, how are names in the block resolved?
Too involved, but basically a form of lexical scoping. Rebol
struggled with this, and details vary by version. Here are the last
docs for version 2:
http://www.rebol.com/r3/docs/concepts/funcs-scope.html
Details changed again for version 3. Best I can tell, Red hasn't
written up its own rules yet.
The model did _not_ support closures naturally (in the sense of local
bindings persisting beyond a function's return). Version 3 added an
alternative to `func`, named `closure`, which could be used when you
wanted a closure:
http://www.rebol.com/r3/docs/datatypes/closure.html
But I noticed just now that Red doesn't have `closure` built in, and
its funcs don't support closures naturally either:
>> adder: func [x] [func [y] [x + y]]
== func [x][func [y] [x + y]]
>> add3: adder 3
== func [y][x + y]
>> add3 12
*** Script Error: x is not in the specified context
*** Where: add3
*** Stack: add3
That's not dynamic scoping, either - it's still unhappy if `x` is
defined at top level:
>> x: 18
== 18
>> add3 12
*** Script Error: x is not in the specified context
*** Where: add3
*** Stack: add3
More information about the Python-ideas
mailing list