[Ecls-list] Trigger action when data structure is updated?

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun Oct 25 11:36:35 UTC 2009


Just to give you an idea, when you define a structure or a class, the
Common Lisp environment creates a number of functions or methods to
access the individual slots. In the case of structures this is rather
strict in the way it is done.

For CLOS objects one can change the class of the class that you are
defining and thus customize the methods that are generated to access
the class methods.

I am doing some emphasis on this because CELLS may or may not be
ported to ECL, but what you want to do can be implemented very easily,
if not in a very efficient way -- to change the slot accessors while
preserving some of the optimizations you may then need to do some more
work.

#+ecl
(setf clos:*optimize-slot-access* nil)

(defclass my-metaclass (standard-class)
  ())

(defmethod (setf clos:slot-value-using-class)
  (value (class my-metaclass) object slot)
  (format t "~&;;; Changing object ~A" object)
  (force-output)
  (call-next-method))

(defclass foo ()
  ((a :initarg :a :accessor foo-a)
   b)
  (:metaclass my-metaclass))

(defparameter *a* (make-instance 'foo :a 4))

(print (foo-a *a*))

(setf (foo-a *a*) 3)

(print (foo-a *a*))


On Sun, Oct 25, 2009 at 12:30 PM, Rui Maciel <rui.maciel at gmail.com> wrote:
>
> Juan Jose Garcia-Ripoll wrote:
>> You can probably cook up the same thing with either a minimal
>> knowledge of CLOS and metaclasses or my hand-crafting the accessors to
>> your slots. However, as it has been pointed out, this is really a
>> Common-Lisp question, not particular to the implementation itself, so
>> there are better places to ask: comp.lang.lisp, Lisp Forum, etc
>
> Sorry about that. I don't have any experience with Lisp but I'm considering
> the idea of relying on Lisp, through ecl, as a scripting language for an
> application I intend to develop. So in order to see if it's a good idea to
> adopt ecl I'm trying to figure out if it is possible to do this sort of stuff to
> begin with. It's nice to know it may be possible to implement the same feature
> without the need for an external library. Nice one.
>
>
> So thanks for the help,
> Rui Maciel
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Ecls-list mailing list
> Ecls-list at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list
>



-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list