core context oriented programming with ContextL
ContextL is a part of the Closer project with contributions from Pascal Costanza and probably others. As per the code repository, it’s actively developed.
(defpackage :a-test
(:use :cl))
(in-package :a-test)
(contextl:define-layered-class
bar ()
((value :initarg :value :layered-accessor bar-value)))
(contextl:define-layered-function bar-incf (f))
(contextl:define-layered-method
bar-incf ((b bar))
(incf (bar-value b)))
(contextl:deflayer log-layer)
(contextl:define-layered-class
bar :in log-layer ()
())
(contextl:define-layered-method
bar-incf :in log-layer :around ((b bar))
(progn
(princ (format nil "~A is incfed" b))
(call-next-method)))
(defparameter +a-bar+
(make-instance 'bar :value 11))
And now, the REPL:
A-TEST> +a-bar+
#<BAR {BEB2581}>
A-TEST> (bar-value +a-bar+)
11
A-TEST> (bar-incf +a-bar+)
12
A-TEST> (bar-value +a-bar+)
12
A-TEST> (contextl:with-active-layers (log-layer) (bar-incf +a-bar+))
#<BAR {BEB2581}> is incfed
13
A-TEST> (bar-value +a-bar+)
13
A-TEST>