• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A difficult Jess rule

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am working on writing a rule to figure out which shadow fact in a group has the latest timestamp. Then use the found out in another rule. All shadow facts are the same java object and the size of the group is changable. If there are only two in the group I know how to achieve the goal, but more than two in a group I could not figure out how to do it. Can someone please help!!!

Thanks in advance
 
Hope Zhu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgot one more thing. I know if I always retract the shadow fact which has the older timestamp then I will only have the latest left. But I may need the old facts to stay in for other rules. So the question should be without retracting any facts how to find out which one is the latest.

Thanks again.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The general way to write this is (pseudocode)



A rule like this will fire just once, for the very latest fact. So, imagine there's a template like

(deftemplate object (slot timestamp (type LONG)))

then the rule might look like

 
reply
    Bookmark Topic Watch Topic
  • New Topic