Hacker News new | ask | show | jobs
by dangom 2827 days ago
I see the example use case is exactly the same as the one given in the python documentation [1]. Any other practical use cases?

[1] https://docs.python.org/3.7/library/collections.html#collect...

2 comments

It's nice for anything with nested scopes -- Example that came to mind since a link to Crafting Interpreters was also on the front page: Variable lookup for for an interpreter. If each scope gets its own set of bindings, you can make a ChainMap from most specific to least specific and look up values from that instead of manually traversing scopes.
If you're implementing some kind of style sheet system, you often want to support a tower of overrides (say, theme → document → chapter → explicitly-marked-section).