Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (0 / 6) |
Uptime: | 48:21:06 |
Calls: | 422 |
Files: | 1,024 |
Messages: | 90,422 |
I need some way to define "local" methods, which can override
temporarily "global" methods and obey some kind of dynamic scoping rule.
I feel that your requirements may be somewhere in the locus of
Pastal Costanza's work, like ContextL.
https://github.com/pcostanza/contextl
Also see Costanza's paper "Dynamically Scoped Functions as the
Essence of AOP" [2003].
Assuming I'm not the first to feel such a need, what are usual
approaches to try and provide that kind of behavior?
Since in Common Lisp we don't have dynamically scoped functions, only variables, the straightforward thing, without using anyone's framework,
would be to use special variables to hold certain functions of interest,
and funcall them. (That can be wrapped or macroed over.)
(defun overridable-fun (&rest args)
(apply *overridable-fun* args))
(let ((*overridable-fun* (lambda (...) ...)))
(overridable-fun 42))
I need some way to define "local" methods, which can override
temporarily "global" methods and obey some kind of dynamic scoping rule.
Assuming I'm not the first to feel such a need, what are usual
approaches to try and provide that kind of behavior?
I need some way to define "local" methods, which can override
temporarily "global" methods and obey some kind of dynamic scoping rule.
I feel that your requirements may be somewhere in the locus of
Pastal Costanza's work, like ContextL.
https://github.com/pcostanza/contextl
Also see Costanza's paper "Dynamically Scoped Functions as the
Essence of AOP" [2003].
Thanks! That's a nice solution, and the underlying implementation
technique makes a lot of sense (it refines the manual solution I've
been playing with).
Assuming I'm not the first to feel such a need, what are usual
approaches to try and provide that kind of behavior?
Since in Common Lisp we don't have dynamically scoped functions, only
variables, the straightforward thing, without using anyone's framework,
would be to use special variables to hold certain functions of interest,
and funcall them. (That can be wrapped or macroed over.)
(defun overridable-fun (&rest args)
(apply *overridable-fun* args))
(let ((*overridable-fun* (lambda (...) ...)))
(overridable-fun 42))
For dynamically-scoped local functions, that's indeed what I typically
use (or alternatively, I simply pass that function explicitly down the stack), but my question is for the case where I want to do it for
methods, i.e. for "part" of a function (I guess I could simulate it by
I suspect Costanza's ContextL may speaks to these requirements.
You are in some scope in which you would like to modify the behavior
of a generic function, so it has different methods. In "COP" (context-oriented programming) that behavior would belong to a layer.
You dynamically activate and deactivate the layer (by name, I think).
The layer defines the methods (so physically they are not locally
enclosed in the scope(s) where you are activating the layer). That's a feature, since you can activate a layer in multiple places.