[cells-devel] make-instance, initarg, c-in

Kenneth Tilton kentilton at gmail.com
Tue Jun 30 22:50:50 UTC 2009



Bastian Müller wrote:
> Hi,
> 
> I'm currently using cells and it works very well,
> except one thing seems a little unhandy:
> 
> When defining a model it's possible to use (c-in ..)
> as an initform to define a slot as a cell, but when
> instantiating a class you have to supply (c-in ...)
> instead the normal value, eg.
> 
> (defmodel x ()
>   ((y :accessor y
>       :initarg :y
>       :initform (c-in nil))
>    ...))
> 
> (let ((test (make-instance 'x :y (c-in 1))))
>   (setf (y test) 2))
> 
> works, but instead sth like
> 
> (let ((test (make-instance 'x :y 1)))
>   (setf (y test) 2))
> 
> would be nice.

I have in fact considered such a thing (making c-input the default) but 
decided it was cray. A premise being that if you need a lot of c-inputs 
you are not really using Cells. So c-input is the rare one, and those 
should stand out and require a declaration from the programmer.

> 
> I tried it with
> 
> (defmethod initialize-instance ((self x) &rest rest)
>   (loop for slot in rest by #'cddr
>      do (let ((value (getf rest slot))
> 	      (name (intern (symbol-name slot))))
> 	  (setf (slot-value self name)
> 		(c-in value)))))
> 
> but I just get:
> 
> The slot CELLS::.CELLS is unbound in the object #<X {10032D5FC1}>.
>    [Condition of type UNBOUND-SLOT]
> 
> Is there any way to get this behavior?

A whole lot of work, off the top of my head, but nothing profound 
cells-wise.

kt





More information about the cells-devel mailing list