Hacker News new | ask | show | jobs
by munificent 2100 days ago
> This isn't dynamic scoping; this is just a global variable with a stack of values.

This isn't a latte; this is just an espresso with steamed milk added to it. :)

What you describe basically is how dynamic scoping is mechanically implemented under the hood.

2 comments

> What you describe basically is how dynamic scoping is mechanically implemented under the hood.

It's certainly how that's commonly emulated but that can leak out e.g. CPython uses threadlocals for decimal contexts, but if you set a localcontext in a coroutine / generator and suspend that, the information leaks out.

I assume the same happens with gevent unless you `patch_thread()`, and even then that assumes `decimal` always deref's threadlocals from the python-level module rather than statically resolve them.

Description !== Implementation