[Openmcl-devel] watched objects

David McClain dbm at refined-audiometrics.com
Mon Sep 28 15:24:43 UTC 2009

... reactive programming built into the kernel, anyone? Great!

On Sep 28, 2009, at 08:18 AM, R. Matthew Emerson wrote:

> There's an experimental new debugging feature in the trunk that allows
> certain lisp objects to be "watched".
> When a write takes place to a watched object, a condition of type
> write-to-watched-object is signaled, and you get a break loop.  You
> can then get a backtrace, etc., to see what happened.  There's a
> restart that will unwatch the object and let you proceed.  You can't
> (yet) say "allow just this one write to happen, but keep the object
> watched."  To continue, you have to unwatch.
> The functions CCL::WATCH and CCL::UNWATCH are the interface to this.
> Silly example:
> ? (defvar *a* (make-array 3))
> *A*
> ? (watch *a*)
> ? (setf (aref *a* 2) 'foo)
>> Error: Write to watched object #<SIMPLE-VECTOR 3> at address
> #xD5018 (uvector index 2).
>> While executing: ASET, in process listener(1).
>> Type :POP to abort, :R for a list of available restarts.
>> Type :? for other options.
> Calling WATCH with no arguments will return a list of objects being
> watched.
> To a reasonable approximation, heap-allocated objects in CCL are
> either UVECTORs or CONSes.  You can watch either kind of object, but
> there are some restrictions.
> Basically everything that isn't cons cell is a uvector (this includes
> all sorts of arrays, functions, symbols, hash-tables, bignums, etc.).
> For vectors, there's a one-to-one correspondence between the uvector
> indicies and the vector indicies.
> For more complicated objects (other arrays, hash tables, etc.), simply
> saying, e.g., (watch *my-2d-array*) won't do what you probably want:
> you'd need to watch the actual data vector, which is one element of
> the uvector that represents the 2d array.
> Although you can watch cons cells, you can watch only indivdual cons
> cells.  This means if you say something like (watch (list 3 4 5)),
> you'll end up watching only the first cons (3 . (4 5)) instead of the
> whole chain of cons cells.
> The way watching objects is currently implemented is fairly simple
> (and simple-minded);  getting rid of these limitations would probably
> involve writing most of a copying GC.
> Anyway, if you want, try it out and let me know how it works (or more
> importantly, if it doesn't).  It is only implemented on x86 for now.
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

Dr. David McClain
dbm at refined-audiometrics.com

More information about the Openmcl-devel mailing list