JESS: Can't use funcalls in backchained patterns?

classic Classic list List threaded Threaded
6 messages Options
hlc
Reply | Threaded
Open this post in threaded view
|

JESS: Can't use funcalls in backchained patterns?

hlc
Hi,

I was trying to make a rule that fires a few seconds after a fact is
asserted. Here is my experiment:

(deftemplate time (slot when))
(do-backward-chaining time)

(defrule do-time
    (need-time (when ?w))
    =>
    (schedule-time-alert ?w) )

(deftemplate k
    (slot when (default-dynamic (call System currentTimeMillis))) )

(defrule r
    (k (when ?w))
    (time (when =(+ ?w 3000)))   ; a time fact 3 seconds after k is expected
    =>
    (printout t "3 seconds after k!" crlf) )

Function schedule-time-alert is implemented in Java and is supposed to
add a fact at the indicated time.
While this approach looks pretty clean to me, it does not even compile.
I am getting a "Can't use funcalls in backchained patterns when", in
rule r. This does not seem to be documented (at least I did not find it).

There is a work arround described in
http://www.jessrules.com/jess/FAQ.shtml#Q9
That approach has been suggested in previous e-mail threads, I have noticed.
But while it seems to work, it is also much more CPU-intensive, as a
number of time events (idle facts in faq Q9) would be added for no reason.

Any thoughts?

Thanks.

Henrique



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Can't use funcalls in backchained patterns?

Friedman-Hill, Ernest
This is quite clever, but as you found, this won't work due to  
limitations in the implementation. But you could skip backward  
chaining altogether and just do something like

(defrule r
    (k (when ?w&:(progn (schedule-time-alert (+ ?w 3000)) TRUE)))
    (time (when =(+ ?w 3000)))   ; a time fact 3 seconds after k is  
expected
    =>
    (printout t "3 seconds after k!" crlf) )

You would not need the progn/TRUE if schedule-time-alert returned a  
true value.


On Jul 21, 2010, at 5:59 AM, Henrique Lopes Cardoso wrote:

> Hi,
>
> I was trying to make a rule that fires a few seconds after a fact is
> asserted. Here is my experiment:
>
> (deftemplate time (slot when))
> (do-backward-chaining time)
>
> (defrule do-time
>    (need-time (when ?w))
>    =>
>    (schedule-time-alert ?w) )
>
> (deftemplate k
>    (slot when (default-dynamic (call System currentTimeMillis))) )
>
> (defrule r
>    (k (when ?w))
>    (time (when =(+ ?w 3000)))   ; a time fact 3 seconds after k is  
> expected
>    =>
>    (printout t "3 seconds after k!" crlf) )
>
> Function schedule-time-alert is implemented in Java and is supposed to
> add a fact at the indicated time.
> While this approach looks pretty clean to me, it does not even  
> compile.
> I am getting a "Can't use funcalls in backchained patterns when", in
> rule r. This does not seem to be documented (at least I did not find  
> it).
>
> There is a work arround described in
> http://www.jessrules.com/jess/FAQ.shtml#Q9
> That approach has been suggested in previous e-mail threads, I have  
> noticed.
> But while it seems to work, it is also much more CPU-intensive, as a
> number of time events (idle facts in faq Q9) would be added for no  
> reason.
>
> Any thoughts?
>
> Thanks.
>
> Henrique
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> [hidden email]'
> in the BODY of a message to [hidden email], NOT to the list
> (use your own address!) List problems? Notify [hidden email]
> .
> --------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            [hidden email]
Livermore, CA 94550                             http://www.jessrules.com





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Can't use funcalls in backchained patterns?

Wolfgang Laun-2
Why wouldn't a simple

(defrule r
   (k (when ?w))
=>
   (schedule-timer-alert (+ ?w 3000))
)

be sufficient?

-W

On 21 July 2010 16:00, Ernest Friedman-Hill <[hidden email]> wrote:

> This is quite clever, but as you found, this won't work due to limitations
> in the implementation. But you could skip backward chaining altogether and
> just do something like
>
> (defrule r
>   (k (when ?w&:(progn (schedule-time-alert (+ ?w 3000)) TRUE)))
>   (time (when =(+ ?w 3000)))   ; a time fact 3 seconds after k is expected
>   =>
>   (printout t "3 seconds after k!" crlf) )
>
> You would not need the progn/TRUE if schedule-time-alert returned a true
> value.
>
>
> On Jul 21, 2010, at 5:59 AM, Henrique Lopes Cardoso wrote:
>
>> Hi,
>>
>> I was trying to make a rule that fires a few seconds after a fact is
>> asserted. Here is my experiment:
>>
>> (deftemplate time (slot when))
>> (do-backward-chaining time)
>>
>> (defrule do-time
>>   (need-time (when ?w))
>>   =>
>>   (schedule-time-alert ?w) )
>>
>> (deftemplate k
>>   (slot when (default-dynamic (call System currentTimeMillis))) )
>>
>> (defrule r
>>   (k (when ?w))
>>   (time (when =(+ ?w 3000)))   ; a time fact 3 seconds after k is expected
>>   =>
>>   (printout t "3 seconds after k!" crlf) )
>>
>> Function schedule-time-alert is implemented in Java and is supposed to
>> add a fact at the indicated time.
>> While this approach looks pretty clean to me, it does not even compile.
>> I am getting a "Can't use funcalls in backchained patterns when", in
>> rule r. This does not seem to be documented (at least I did not find it).
>>
>> There is a work arround described in
>> http://www.jessrules.com/jess/FAQ.shtml#Q9
>> That approach has been suggested in previous e-mail threads, I have
>> noticed.
>> But while it seems to work, it is also much more CPU-intensive, as a
>> number of time events (idle facts in faq Q9) would be added for no reason.
>>
>> Any thoughts?
>>
>> Thanks.
>>
>> Henrique
>>
>>
>>
>> --------------------------------------------------------------------
>> To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
>> in the BODY of a message to [hidden email], NOT to the list
>> (use your own address!) List problems? Notify [hidden email].
>> --------------------------------------------------------------------
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            [hidden email]
> Livermore, CA 94550                             http://www.jessrules.com
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
> in the BODY of a message to [hidden email], NOT to the list
> (use your own address!) List problems? Notify [hidden email].
> --------------------------------------------------------------------
>
>




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Can't use funcalls in backchained patterns?

Friedman-Hill, Ernest
It would, but then you'd need a second rule to actually act on the  
alert. I think Henrique was looking for a way to do it in one rule,  
imagining that there would be many triggers like this.


On Jul 21, 2010, at 10:05 AM, Wolfgang Laun wrote:

> Why wouldn't a simple
>
> (defrule r
>   (k (when ?w))
> =>
>   (schedule-timer-alert (+ ?w 3000))
> )
>
> be sufficient?
>
> -W
>

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

hlc
Reply | Threaded
Open this post in threaded view
|

Re: JESS: Can't use funcalls in backchained patterns?

hlc
That's correct.

Furthermore, I want to generate (time) facts only if they are used in
the LHS of a rule, not in other uses of (k) patterns. That was the point
of using back-chain.
Another issue is that rules are added at runtime. I may have some rules
of the form

   (k (when ?w)
   (time (when =(+ ?w ...)))
   => ...

but also some other rules of the form

   (k (when ?w)
   => ...

Doing the
    &:(progn (schedule-time-alert (+ ?w 3000)) TRUE)
thing in all rules of the former type is just more troublesome.

But if that's the only solution, maybe I'll stick to it.

Thanks.

Henrique



Ernest Friedman-Hill wrote:

> It would, but then you'd need a second rule to actually act on the
> alert. I think Henrique was looking for a way to do it in one rule,
> imagining that there would be many triggers like this.
>
>
> On Jul 21, 2010, at 10:05 AM, Wolfgang Laun wrote:
>
>> Why wouldn't a simple
>>
>> (defrule r
>>   (k (when ?w))
>> =>
>>   (schedule-timer-alert (+ ?w 3000))
>> )
>>
>> be sufficient?
>>
>> -W
>>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences, Sandia National Laboratories
> PO Box 969, MS 9012, Livermore, CA 94550
> http://www.jessrules.com
>
>
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
> in the BODY of a message to [hidden email], NOT to the list
> (use your own address!) List problems? Notify
> [hidden email].
> --------------------------------------------------------------------
>
>

--
----- - - - - -  -  -  -  -  -   -   -
Henrique Lopes Cardoso
DEI/FEUP
Rua Dr. Roberto Frias | 4200-465 Porto
PORTUGAL
(+351)225081400 ext.1315
[hidden email] | www.fe.up.pt/~hlc
----- - - - - -  -  -  -  -  -   -   -



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Can't use funcalls in backchained patterns?

Wolfgang Laun-2
In reply to this post by Friedman-Hill, Ernest
On 21 July 2010 16:22, Ernest Friedman-Hill <[hidden email]> wrote:
> It would, but then you'd need a second rule to actually act on the alert. I
> think Henrique was looking for a way to do it in one rule, imagining that
> there would be many triggers like this.

OK - but I understood that the ultimate goal is the insertion of whatever
schedule-timer-alert inserts, after the 3000ms. But Henrique will know ;-)

>
>
> On Jul 21, 2010, at 10:05 AM, Wolfgang Laun wrote:
>
>> Why wouldn't a simple
>>
>> (defrule r
>>  (k (when ?w))
>> =>
>>  (schedule-timer-alert (+ ?w 3000))
>> )
>>
>> be sufficient?
>>
>> -W
>>
>
> ------------------




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------