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.
- Host: GitHub
- URL: https://github.com/buckley-w-david/dynamic-scope
- Owner: buckley-w-david
- Created: 2022-08-28T20:43:54.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-28T20:44:00.000Z (about 3 years ago)
- Last Synced: 2025-01-28T02:12:26.619Z (8 months ago)
- Language: Python
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```