Josip Gracin | 4 May 2007 01:09
Picon

Lots of instances, callback when particular instance changes

Hello!

I have the following class

	(defmodel switch (component)
	  ((pos :initarg :pos
		:initform (c-in :off)
		:accessor switch-position)))

and I've created lots of switches in a family and I can find them by 
name.  Is there any elegant way of establishing a dependency between one 
particular instance of switches and some code?  I mean, like a callback 
function to be called when the value of that switch changes?

If I use def-c-output on 'pos', it will get called whenever any of the 
switch instances sets it.

Thanks!
Josip Gracin | 4 May 2007 22:41
Picon

Re: Lots of instances, callback when particular instance changes

Here's what I'm currently doing (just an outline):

(defmodel switch (component)
   ((switch-position :cell t
                     :initarg :switch-position
                     :initform (c-in :off)
                     :accessor switch-position)
    (change-handler :cell nil
                    :initform nil
                    :initarg :change-handler
                    :reader switch-change-handler)))

(def-c-output switch-position (self new-value old-value)
   (when (switch-change-handler self)
     (funcall (switch-change-handler self) self new-value old-value)))

And then create instances:

...
(mksys 'switch :main-battery-switch)
(mksys 'switch :apu-start-switch                           			 
:change-handler 'apu-start-switch-change-handler)
...

The reason I need the change handler is that the change handler has to 
modify the value of the self switch.  For example, when apu-start-switch 
changes its value to :START, change handler schedules an action which 
will set the switch back to :ON after some time.  I fail to see how I 
can do this using regular slot-dependency mechanisms provided by Cells.

(Continue reading)

Frank Goenninger | 5 May 2007 12:02
Picon

Re: Lots of instances, callback when particular instance changes

Hi -

Am 04.05.2007 um 22:41 schrieb Josip Gracin:

> Here's what I'm currently doing (just an outline):
>
> (defmodel switch (component)
>   ((switch-position :cell t
>                     :initarg :switch-position
>                     :initform (c-in :off)
>                     :accessor switch-position)
>    (change-handler :cell nil
>                    :initform nil
>                    :initarg :change-handler
>                    :reader switch-change-handler)))
>
>
> (def-c-output switch-position (self new-value old-value)
>   (when (switch-change-handler self)
>     (funcall (switch-change-handler self) self new-value old-value)))
>
> And then create instances:
>
> ...
> (mksys 'switch :main-battery-switch)
> (mksys 'switch :apu-start-switch                            
> 			 :change-handler 'apu-start-switch-change-handler)
> ...
>
> The reason I need the change handler is that the change handler has  
(Continue reading)

Josip Gracin | 6 May 2007 00:04
Picon

Re: Lots of instances, callback when particular instance changes

Frank Goenninger wrote:
> You do - yet there is another approach I adopted from Kenny:

Thanks!  Now I have to spend some time examining stuff you've written 
that I've never heard of before (such as with-integrity...). :-)  Also, 
there doesn't seem to be anything named "defobserver" in the latest 
asdf-installable cells.  Has this become def-c-output perhaps?

Anyway, I was kind of trying to avoid sub-classing because I have lots 
of switches.  I'll have to re-think that decision.
Frank Goenninger | 6 May 2007 00:23
Picon

Re: Lots of instances, callback when particular instance changes

Am 06.05.2007 um 00:04 schrieb Josip Gracin:

> Frank Goenninger wrote:
>> You do - yet there is another approach I adopted from Kenny:
>
> Thanks!  Now I have to spend some time examining stuff you've  
> written that I've never heard of before (such as with- 
> integrity...). :-)

> Also, there doesn't seem to be anything named "defobserver" in the  
> latest asdf-installable cells.  Has this become def-c-output perhaps?

You definitely should get the CVS sources from common-lisp.net! See  
there for how to access the CVS repository... -

def-c-output (sort of) became defobserver ... Also, there's a big  
chance you won't find with-integrity in the asdf-installable sources...

>
> Anyway, I was kind of trying to avoid sub-classing because I have  
> lots of switches.  I'll have to re-think that decision.

Yeah, it took some time for me too to take that decision. And it  
still is very situation/use case-dependent, so there's no "always go  
that route" rule available, IMO. Still, I don't mind heaving a few  
hundred classes defined in my Lisp programs (using AllegroCL 8 here).

Kenny is surprisingly quiet ... Maybe he's busy taking orders for his  
new AlgebraOne software ;-)

(Continue reading)

Josip Gracin | 6 May 2007 14:11
Picon

Re: Lots of instances, callback when particular instance changes

Frank Goenninger wrote:
> You definitely should get the CVS sources from common-lisp.net! See 
> there for how to access the CVS repository... -

I thought asdf-install was pretty much in sync with the CVS.  Oh well...

OTOH, "check it out from CVS" is easier said than done, since none of 
the links to the CVS tree that I was able to find were valid.  In the 
end I had to guess the correct location.  Here it is, in case anyone is 
interested:

cvs -z3 -d:pserver:anonymous <at> common-lisp.net:/project/cells/cvsroot co cells

Josip Gracin | 9 May 2007 22:05
Picon

How to delay evaluation of defobserver?

Hello!

I've successfully ported my application from cells2.0 to Cells3.  Cells3 
looks very nice indeed.  When needed, I've used c_? to delay evaluation 
and it worked great.  However, I also have some observers defined with 
defobserver and I'd like them to be lazily evaluated because they depend 
on some not-yet-created instances.  Is there a way to do this?
Josip Gracin | 9 May 2007 23:03
Picon

Re: How to delay evaluation of defobserver?

Josip Gracin wrote:
> and it worked great.  However, I also have some observers defined with 
> defobserver and I'd like them to be lazily evaluated because they depend 
> on some not-yet-created instances.  Is there a way to do this?

Of course.  Just define the observers after you've created all the 
instances.  Oh well...

This does make the code layout uglier because I have to move all the 
defobservers to some file which will be loaded after all other files. 
Is there a better way to organize this?
Ken Tilton | 10 May 2007 00:01
Picon

test (ignore)

test

<div><p>test
</p></div>
Ken Tilton | 10 May 2007 00:03
Picon

Fwd: How to delay evaluation of defobserver?

[Sorry if folks have seen this before, but I haven't, so not sure what is going on. - kt]

---------- Forwarded message ----------
From: Ken Tilton < kentilton <at> gmail.com>
Date: May 9, 2007 5:12 PM
Subject: Re: [cells-devel] How to delay evaluation of defobserver?
To: Josip Gracin < gracin <at> tel.fer.hr>

Not sure what is going on. I sent this to the list and you earlier from another mail account and apparently neither got thru. Trying again direct from google mail. Saw your second note. Nah, I would do anything with load order. But this is a design question, which means it cannot be answered in the abstract (which is what I cover below). kt

Josip Gracin wrote:

Hello!

I've successfully ported my application from cells2.0 to Cells3.  Cells3 looks very nice indeed.  When needed, I've used c_? to delay evaluation and it worked great.  However, I also have some observers defined with defobserver and I'd like them to be lazily evaluated because they depend on some not-yet-created instances.  Is there a way to do this?

You might have to provide an example, distilled from your application if the whole thing would be too much. Are you saying obersvers are getting called even before the lazy cell got kicked off? Or do you mean, OK, the lazy cell gets kicked off when expected, but now I further want to defer the observer running? Or is this unrelated to lazy cells? ie, You have a normal cell but you want the observer deferred? But then, OK, how do you indicate when the laziness ends and the observer should fire? Presumably you want a rule X that terminates laziness and activates an observer. If so, you could just code up:

 (defobserver .....
     (when X ;; in your case, (fm-includes self <whavtever>)
          <stuff that depends on whatever>))

Depending on the design, you might also consider having a Cell that says "OK, now the model has reached this state", part of which is determined by these other instances coming into existence. Then you either hang your observer off that new state variable or check that state variable in the observer.

kt




-- 
Ken Tilton                   Theory Y Learning        ken <at> theoryyalgebra.com              2112 Baileys Corner Rd   http://www.theoryyalgebra.com     Wall, NJ 07719           732-359-6038 | 646-269-1077 (m)



<div>
<p>[Sorry if folks have seen this before, but I haven't, so not sure what is going on. - kt]<br><br>---------- Forwarded message ----------<br><span class="gmail_quote">From: Ken Tilton &lt;
<a href="mailto:kentilton <at> gmail.com">kentilton <at> gmail.com</a>&gt;<br>Date: May 9, 2007 5:12 PM<br>Subject: Re: [cells-devel] How to delay evaluation of defobserver?<br>To: Josip Gracin &lt;<a href="mailto:gracin <at> tel.fer.hr">
gracin <at> tel.fer.hr</a>&gt;<br><br></span>Not sure what is going on. I sent this to the list and you earlier from another mail account and apparently neither got thru. Trying again direct from google mail. Saw your second note. Nah, I would do anything with load order. But this is a design question, which means it cannot be answered in the abstract (which is what I cover below). kt
<br><br></p>
<div lang="x-unicode">
<span class="q">Josip Gracin wrote:
<br><br><blockquote type="cite">Hello!
<br><br>I've successfully ported my application from cells2.0 to Cells3.&nbsp; 
Cells3 looks very nice indeed.&nbsp; When needed, I've used c_? to delay 
evaluation and it worked great.&nbsp; However, I also have some observers 
defined with defobserver and I'd like them to be lazily evaluated 
because they depend on some not-yet-created instances.&nbsp; Is there a way 
to do this?
<br>
</blockquote></span>
<br>You might have to provide an example, distilled from your application if 
the whole thing would be too much. Are you saying obersvers are getting 
called even before the lazy cell got kicked off? Or do you mean, OK, the 
lazy cell gets kicked off when expected, but now I further want to defer 
the observer running? Or is this unrelated to lazy cells? ie, You have a 
normal cell but you want the observer deferred? But then, OK, how do you 
indicate when the laziness ends and the observer should fire? Presumably 
you want a rule X that terminates laziness and activates an observer. If 
so, you could just code up:
<br><br>&nbsp;(defobserver .....
<br>&nbsp;&nbsp;&nbsp;&nbsp; (when X ;; in your case, (fm-includes self &lt;whavtever&gt;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;stuff that depends on whatever&gt;))
<br><br>Depending on the design, you might also consider having a Cell that says 
"OK, now the model has reached this state", part of which is determined 
by these other instances coming into existence. Then you either hang 
your observer off that new state variable or check that state variable 
in the observer.
<br><br>kt
<br><br><br><br><br><div>
<span>--&nbsp;<br></span>Ken Tilton&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Theory Y Learning&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="mailto:ken <at> theoryyalgebra.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">ken <at> theoryyalgebra.com</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
2112 Baileys Corner Rd&nbsp;&nbsp; <a href="http://www.theoryyalgebra.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.theoryyalgebra.com</a>&nbsp;&nbsp;&nbsp;&nbsp; 
Wall, NJ 07719&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 732-359-6038 | 646-269-1077 (m)
<br><br><br><br>
</div>
</div>
</div>

Gmane