An open API service indexing awesome lists of open source software.

https://github.com/buckley-w-david/dynamic-scope

A library that changes the binding properties of closure variables, mimicing dynamic scoping rules.
https://github.com/buckley-w-david/dynamic-scope

Last synced: 7 months ago
JSON representation

A library that changes the binding properties of closure variables, mimicing dynamic scoping rules.

Awesome Lists containing this project

README

          

# dynamic-scope

A library that changes the binding properties of closure variables, mimicing dynamic scoping rules.

```python
>>> from dynamic_scope import dynamic, inject
>>> def make_functions():
... # value has to be defined locally in a parent scope
... # otherwise the generated bytecode in the functions will treat it
... # as a global
... value = 0
... def normal():
... return value
... @dynamic
... def dyn():
... return value
... return normal, dyn
...
>>> value = 1
>>> normal, dyn = make_functions()
>>> assert normal() == 0
>>> assert dyn() == 1
>>> value = 2
>>> assert normal() == 0
>>> assert dyn() == 2
```