Hi Michael,
I thought I remembered responding to your post, but apparently I did
not. In any case, this is a good suggestion, and one that I will
incorporate into a future version of Jess. Right now, though, there
isn't such a command. You could write one in Java but you'd need to
modify the reflect/* classes. Alternatively, you could do
some housekeeping yourself: each time you do a definstance, store a
reference to the object somewhere; then write some command to
undefinstance all of the listed objects. Hmmm. Something like this
(This is untested and un-proofread code, intended for use with Jess 4.x):
(deffunction my-definstance (?class ?obj)
(definstance ?class ?obj)
(store-definstance ?obj))
(deffunction my-undefinstance (?class ?obj)
(undefinstance ?obj)
(remove-definstance ?obj))
....
public class MyDefinstanceStuff {
private static Hashtable m_ht = new Hashtable();
private String m_name;
public MyDefinstanceStuff(String name) { m_name = name;}
public String name() { return m_name; }
public Value call(ValueVector args, Context c)
{
if (m_name.equals("store-definstance"))
m_ht.put(args.get(1).externalAddressValue(),
args.get(1).externalAddressValue());
else if (m_name.equals("remove-definstance"))
m_ht.remove(args.get(1).externalAddressValue());
else // remove-all-definstances
{
for (Enumeration e=m_ht.elements(); e.hasMoreElements();)
{
c.engine().store("temp", e.nextElement());
c.engine().executeCommand("(undefinstance (fetch temp))");
}
m_ht.clear();
}
return Funcall.TRUE;
}
...
rete.addUserfunction(new MyDefinstanceStuff("store-definstance"))
rete.addUserfunction(new MyDefinstanceStuff("remove-definstance"))
rete.addUserfunction(new MyDefinstanceStuff("remove-all-definstances"))
...
Then write your Jess code interms of my-definstance and
my-undefinstance and call remove-all-definstances when you want to.
I think Michael Lucero wrote:
>
> Ernest,
>
> I sent this out to the mailing list last week, but haven't got any
> response. I'd appreciate your input.
>
>
>---------------------------------------------------------------------------------------
>
> Is there an 'easy' way to undefinstance all definstance's?
>
> Since 'reset' does not retract the definstances from the engine, it
> would be nice if there was some way (like undefinstance *) to get rid of
>
> all definstances without writing many rules to clean them out.
>
> I'm working with Jess 4.3
>
> Thanks,
> Michael Lucero
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------