RE: JESS: [EXTERNAL] Adding facts that are instances of from-class deftemplates
"Friedman-Hill, Ernest" <[email protected]> Fri, 10 May 2013 14:21:52 +0000
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
--_000_7F2CAF6713AFDD4392FC4DAA05671E072C79AC8CEXMB10srnsandia_ Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable The *real* way to add shadow facts is using the "definstance" function. It = has a number of options that aren't available with "add". The "add" functio= n was added to Jess to support the simplified semantics of JSR-94 (the java= x.rules API) but the intent is that most Jess users will use "definstance." Asserting a fact directly from a from-class template is like buying a dogho= use; you don't expect to go out the next morning and find that somehow it h= as a dog in it, right? It's certainly something you can do, but in normal l= ife it's not very useful; usually you get a doghouse when you buy a dog, an= d "add" and "definstance" will both get you a doghouse for your Java object= "dog" automatically. From: [email protected] [mailto:[email protected]] On B= ehalf Of Henrique Lopes Cardoso Sent: Friday, May 10, 2013 4:54 AM To: jess-users Subject: JESS: [EXTERNAL] Adding facts that are instances of from-class def= templates Hi, I am concerned with the at least two different ways in which you can add, t= o working memory, facts that are instances of from-class deftemplates. Lets say I have: (deftemplate FC (declare (from-class FC))) I can add a shadow fact like this: (bind ?fc (new FC)) (add ?fc) This is the general approach described in Section 5.3.2 of the Jess manual. But I can also simply go like: (assert (FC)) I guess in this case I do not get a shadow fact, since the OBJECT slot is n= il. So, my question is: if my facts are not supposed to be changed from Java co= de, is there any difference in using each of these approaches? Section 5.3 from the Jess manual does not even mention that instances of fr= om-class deftemplates can be created using the second approach above. Thanks! Henrique --_000_7F2CAF6713AFDD4392FC4DAA05671E072C79AC8CEXMB10srnsandia_ Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr= osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:= //www.w3.org/TR/REC-html40"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > <meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)"> <style><!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","serif";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-reply; font-family:"Calibri","sans-serif"; color:#1F497D;} .MsoChpDefault {mso-style-type:export-only; font-family:"Calibri","sans-serif";} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3D"EN-US" link=3D"blue" vlink=3D"purple"> <div class=3D"WordSection1"> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1F497D">The *<b>real</b>* way to = add shadow facts is using the “definstance” function. It has a = number of options that aren’t available with “add”. The &= #8220;add” function was added to Jess to support the simplified semantics of JSR-94 (the javax= .rules API) but the intent is that most Jess users will use “definsta= nce.”<o:p></o:p></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1F497D"><o:p> </o:p></span><= /p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1F497D">Asserting a fact directly= from a from-class template is like buying a doghouse; you don’t expe= ct to go out the next morning and find that somehow it has a dog in it, right? It’s certainly something you can do, but in normal lif= e it’s not very useful; usually you get a doghouse when you buy a dog= , and “add” and “definstance” will both get you a d= oghouse for your Java object “dog” automatically.<o:p></o:p></s= pan></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri","sans-serif";color:#1F497D"><o:p> </o:p></span><= /p> <p class=3D"MsoNormal"><b><span style=3D"font-size:10.0pt;font-family:"= ;Tahoma","sans-serif"">From:</span></b><span style=3D"font-s= ize:10.0pt;font-family:"Tahoma","sans-serif""> owner-je= [email protected] [mailto:[email protected]] <b>On Behalf Of </b>Henrique Lopes Cardoso<br> <b>Sent:</b> Friday, May 10, 2013 4:54 AM<br> <b>To:</b> jess-users<br> <b>Subject:</b> JESS: [EXTERNAL] Adding facts that are instances of from-cl= ass deftemplates<o:p></o:p></span></p> <p class=3D"MsoNormal"><o:p> </o:p></p> <div> <p class=3D"MsoNormal">Hi,<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">I am concerned with the at least two different ways = in which you can add, to working memory, facts that are instances of from-c= lass deftemplates.<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal">Lets say I have:<o:p></o:p></p> </div> <div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">(deftemplate FC (declare (from-class FC)))<o:p></o:p= ></p> </div> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">I can add a shadow fact like this:<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">(bind ?fc (new FC))<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal">(add ?fc)<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">This is the general approach described in Section 5.= 3.2 of the Jess manual.<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal">But I can also simply go like:<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">(assert (FC))<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">I guess in this case I do not get a shadow fact, sin= ce the OBJECT slot is nil.<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">So, my question is: if my facts are not supposed to = be changed from Java code, is there any difference in using each of these a= pproaches?<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal">Section 5.3 from the Jess manual does not even menti= on that instances of from-class deftemplates can be created using the secon= d approach above.<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">Thanks!<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> <div> <p class=3D"MsoNormal">Henrique<o:p></o:p></p> </div> <div> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> </div> </body> </html> --_000_7F2CAF6713AFDD4392FC4DAA05671E072C79AC8CEXMB10srnsandia_--