Message from discussion
Problem with initial value of a shared slot and put-<slot> before and after message handler
Received: by 10.58.170.4 with SMTP id ai4mr634334vec.10.1346932973173;
Thu, 06 Sep 2012 05:02:53 -0700 (PDT)
X-BeenThere: clipsesg@googlegroups.com
Received: by 10.221.0.70 with SMTP id nl6ls406190vcb.5.gmail; Thu, 06 Sep 2012
05:02:50 -0700 (PDT)
Received: by 10.52.67.12 with SMTP id j12mr138166vdt.7.1346932970510;
Thu, 06 Sep 2012 05:02:50 -0700 (PDT)
Date: Thu, 6 Sep 2012 05:02:50 -0700 (PDT)
From: Artem Novikov <noviko...@gmail.com>
To: clipsesg@googlegroups.com
Message-Id: <9d1c8a45-70fc-40f7-9eef-cce205c0cae7@googlegroups.com>
In-Reply-To: <3b7b51ce-18e1-42ee-a508-f80e3bb2f351@googlegroups.com>
References: <3b7b51ce-18e1-42ee-a508-f80e3bb2f351@googlegroups.com>
Subject: Re: Problem with initial value of a shared slot and put-<slot>
before and after message handler
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2393_31037193.1346932970141"
------=_Part_2393_31037193.1346932970141
Content-Type: multipart/alternative;
boundary="----=_Part_2394_4912313.1346932970141"
------=_Part_2394_4912313.1346932970141
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I'm not sure, but the default value of an abstract class? May be a value=20
specified in a derived class?
=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 5 =D1=81=D0=B5=D0=BD=D1=82=D1=8F=D0=B1=D1=
=80=D1=8F 2012 =D0=B3., 21:44:07 UTC+8 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C fs =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=
=B0=D0=BB:
>
> I try to implement a before and after message-handler for an abstract=20
> class which should read a value from a subclassed instance which will=20
> determine the action taken. The subclass is a concrete class which has a=
=20
> shared 'detal-type' slot, which has a default value.
> Basically, the code looks like this:
>
> (defclass MAIN::ROOT
> (is-a USER)
> (role abstract)
> (slot amount (type NUMBER) (default 0)))
>
> (defclass MAIN::A
> (is-a ROOT)
> (role concrete)
> (slot detail-type (access read-only) (storage shared) (default=20
> the-a-type)))
>
> (defmessage-handler MAIN::ROOT put-amount before (?value)
> (bind ?old-value (send ?self get-amount))
> (if (numberp ?old-value) then
> (printout t "Subtract old amount from " (send ?self get-detail-type) " "=
=20
> ?old-value crlf)
> else
> (printout t "ROOT put-amount before ignored" crlf)))
> (defmessage-handler MAIN::ROOT put-amount after (?value)
> (bind ?new-value (send ?self get-amount))
> (if (numberp ?new-value) then
> (printout t "Add new amount to " (send ?self get-detail-type) " "=20
> ?new-value crlf)
> else
> (printout t "ROOT put-amount after ignored" crlf)))
>
> (definstances MAIN::instances
> ([inst-1] of A (amount 25))
> ([inst-2] of A (amount 1000)))
>
> This is the output:
>
> CLIPS> (reset)
> ROOT put-amount before ignored
> Add new amount to nil 25
> ROOT put-amount before ignored
> Add new amount to the-a-type 1000
>
> The problem is with the nil in the first Add new... line. The first time=
=20
> an instance is created, the default value isn't available yet in the=20
> put-amount after handler. The second time, all works fine. I was expectin=
g=20
> the default value to be available in the put after handler!
>
> Questions:
> At what time is the default value assigned to a (shared) slot?
> Is this a bug or do I miss something more fundamental?
>
> I use a work-around by adding a void instance of class A which is ignored=
=20
> by the rest of the program, however I hate work-arounds.
>
>
------=_Part_2394_4912313.1346932970141
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I'm not sure, but the default value of an abstract class? May be a value sp=
ecified in a derived class?<br><br>=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 5 =D1=81=
=D0=B5=D0=BD=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2012 =D0=B3., 21:44:07 UTC+=
8 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C =
fs =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;">I try to implement a before and after message-handler for a=
n abstract class which should read a value from a subclassed instance which=
will determine the action taken. The subclass is a concrete class which ha=
s a shared 'detal-type' slot, which has a default value.<div>Basically, the=
code looks like this:</div><div><br></div><div><div>(defclass MAIN::ROOT</=
div><div><span style=3D"white-space:pre">=09</span>(is-a USER)</div><div><s=
pan style=3D"white-space:pre">=09</span>(role abstract)</div><div><span sty=
le=3D"white-space:pre">=09</span>(slot amount (type NUMBER) (default 0)))</=
div><div><br></div><div>(defclass MAIN::A</div><div><span style=3D"white-sp=
ace:pre">=09</span>(is-a ROOT)</div><div><span style=3D"white-space:pre">=
=09</span>(role concrete)</div><div><span style=3D"white-space:pre">=09</sp=
an>(slot detail-type (access read-only) (storage shared) (default the-a-typ=
e)))</div><div><br></div><div>(defmessage-handler MAIN::ROOT put-amount bef=
ore (?value)</div><div><span style=3D"white-space:pre">=09</span>(bind ?old=
-value (send ?self get-amount))</div><div><span style=3D"white-space:pre">=
=09</span>(if (numberp ?old-value) then</div><div><span style=3D"white-spac=
e:pre">=09=09</span>(printout t "Subtract old amount from " (send ?self get=
-detail-type) " " ?old-value crlf)</div><div><span style=3D"white-space:pre=
">=09</span>else</div><div><span style=3D"white-space:pre">=09=09</span>(pr=
intout t "ROOT put-amount before ignored" crlf)))</div><div><span style=3D"=
white-space:pre">=09</span></div><div>(defmessage-handler MAIN::ROOT put-am=
ount after (?value)</div><div><span style=3D"white-space:pre">=09</span>(bi=
nd ?new-value (send ?self get-amount))</div><div><span style=3D"white-space=
:pre">=09</span>(if (numberp ?new-value) then</div><div><span style=3D"whit=
e-space:pre">=09=09</span>(printout t "Add new amount to " (send ?self get-=
detail-type) " " ?new-value crlf)</div><div><span style=3D"white-space:pre"=
>=09</span>else</div><div><span style=3D"white-space:pre">=09=09</span>(pri=
ntout t "ROOT put-amount after ignored" crlf)))</div><div><br></div><div>(d=
efinstances MAIN::instances</div><div><span style=3D"white-space:pre">=09</=
span>([inst-1] of A (amount 25))</div><div><span style=3D"white-space:pre">=
=09</span>([inst-2] of A (amount 1000)))</div></div><div><br></div><div>Thi=
s is the output:</div><div><br></div><div><div>CLIPS> (reset)</div><div>=
ROOT put-amount before ignored</div><div>Add new amount to nil 25</div><div=
>ROOT put-amount before ignored</div><div>Add new amount to the-a-type 1000=
</div></div><div><br></div><div>The problem is with the nil in the first Ad=
d new... line. The first time an instance is created, the default value isn=
't available yet in the put-amount after handler. The second time, all work=
s fine. I was expecting the default value to be available in the put after =
handler!</div><div><br></div><div>Questions:</div><div>At what time is the =
default value assigned to a (shared) slot?</div><div>Is this a bug or do I =
miss something more fundamental?</div><div><br></div><div>I use a work-arou=
nd by adding a void instance of class A which is ignored by the rest of the=
program, however I hate work-arounds.</div><div><br></div></blockquote>
------=_Part_2394_4912313.1346932970141--
------=_Part_2393_31037193.1346932970141--