A (not very good) example in pseudocode would be:
complicated_operation(param) with context (log_out=myfile);
// complicated_operation calls a function,
// that calls another function...
void log(string str) context (File log_out=stdout) {...};
This would be a bit like TLS, but has the advantage that the context reverts after the original call.Usually, when I have this problem, I just stuff all the functions into a class, and make the "context" private fields. But then you end up with classes that really "don't want to" be classes, the lifetime of the context state is longer than necessary and unclear, and it feels like a hack. Also, in many languages going from free functions (and plain data and closures) to classes takes a bit of rewriting due to different syntax.
The only language I'm aware of that has these "dynamic scopes" is (apparently) Emacs Lisp, but it should be possible to fake them in C++ quite well.
It would also make the situation in the article a lot cleaner, IMO.