2 ms·
A general concept here is of a "context", which both Ruby blocks and Python context managers try to provide. Something happens when you enter the context, your
by nerdponx 3y ago
A general concept here is of a "context", which both Ruby blocks and Python context managers try to provide. Something happens when you enter the context, your code runs, and then something happens when you exit the context, maybe varying depending on how you exited.
Such "contexts" are somewhat ad hoc in Lisp, whereas Ruby and Python have built-in language support and special syntax for them. The traditional Lisp idea is that you don't need special language support when you have macros and higher-order functions, but the special language support also means that all context managers follow the same protocols, whereas ad hoc contexts introduced by CALL-WITH-FOO/WITH-FOO are more like a common loose convention than a standardized system.
Functional programmers have also understood this idea of structured contexts for a very long time, giving us Functor, Applicative, and Monad.
- lispm 3y agoOne other way to deal with 'context' in Lisp is for example by the ADVICE mechanism or the method combinations (:around, :before, :after, ...) of CLOS. https://en.wikipedia.org/wiki/Advice_(programming) https://en.wikipedia.org/wiki/Advice_(programming) > all context managers follow the same protocols Lisp is an old language with lots of dialects and systems. Thus people had different needs for context management and different facilities available to implement it.
- LanternLight83 3y ago> Lisp is an old language with lots of dialects and systems. Absolutely, my first thought was `dynamic-wind`. https://www.gnu.org/software/guile/manual/html_node/Dynamic-Wind.html https://www.gnu.org/software/guile/manual/html_node/Dynamic-...