ContextL is a CLOS extension for Context-oriented Programming. Currently, there is no documentation available, but you can find a small test case in the distribution and an introduction to ContextL's features in a first overview paper.

The paper says:

We present ContextL,a language extension for the Common Lisp Object System that allows for Context-oriented Programming. It provides means to associate partial class and method definitions with layers and to activate such layers in the control flow of a running program. When a layer is activated, the partial definitions become part of the program until this layer is deactivated. This has the effect that the behavior of a program can be modified according to the context of its use without the need to mention such context dependencies in the affected base program. We illustrate these ideas by describing a way to a)provide different UI views on the same object while b)keeping the conceptual simplicity of OOP that objects know themselves how to behave, in this case how to display themselves. These seemingly contradictory goals can be achieved by separating out class definitions into separate layers instead of separating out the display code into different classes.

Sounds kinda like AOP to me. It intriguings, anyway.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Better than AOP

The "standard AOP model" (if there is such thing)generally modifies code at cut and join "points" in the program's static flow graph. This paradigm looks at control graph "regions" as opposed to points and rather than invoking code at discrete points in the control flow, dynamically modifies the executing code depending on which region (or combination thereof) you're in. It reduces to the standard AOP model when you are able to define a degenerate region as a point within the flow graph. It also appears that you can do this dynamically as well as statically. This is a really interesting and exciting idea.

Praise from an excitable fanboy

After skimming through this paper, I offer the following soundbite summary:

Let's reify context-dependent behaviour.

It's such a simple idea, and with so much mileage! I'm definitely having a Why hasn't anybody thought of this before? moment.

I have a rule-of-thumb about PL design: If somebody documents a design pattern, look for the inadequacy in the PL that the pattern is trying to solve. This paper eliminates Model-View-Controller. 'Nuff said.

What? MVC is bad???

I stopped reading at 'MVC is complex, so knowledge is moved into view objects'.

MVC is not complex at all. I don't know if it is complex in CLOS, but i've used the MVC pattern in C++ and Java in huge projects successfully from database-driven web apps to real-time military applications.

Personally I don't think that introducing yet another concept is good.

Haskellised layers?

Wonder how easy it'd be to implement something similar in Haskell using monad transformers and type classes? You'd use transformers on the transformer stack as layers, runTransformer functions to introduce them and type classes to carry layer-specific information. Better yet, the type system can already represent dependencies between layers.

I always invent things after they've already been invented...

Here and I thought that I came up with this idea! Though I have a slight variation... I want to use css-like selectors to tell the code how to behave in a given context. See my scribled notes on Code Selectors.

List of "Context" Resources

For those who are interested in ContextL, I have an extensive list of related links which you may also find interesting.