JESS: Iteration over list

View: New views
20 Messages — Rating Filter:   Alert me  

JESS: Iteration over list

by Levent Kent :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
    (depends-on (parent ?a) (children ?list))
    (foreach ?c ?list  (available-part (name ?c)))
    =>
    (assert (available-part (name ?a)))
    )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent

Re: JESS: Iteration over list

by nick-210 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Levent,

You are using a function (foreach) at the LHS of a rule. See
http://www.jessrules.com/FAQ.shtml#Q17 for an explanation on why this is
not good practice.
Try putting the foreach loop on the RHS of the rule, and most likely
things will work as expected.

(defrule BuildPlanForward
    (depends-on (parent ?a) (children ?list))
    =>
    (foreach ?c ?list (assert (available-part (name ?a))))

- Nick.

levent kent wrote:

> Hi  everybody,
>
> I am doing my masters thesis and have a problem with lists.
> It is actually very simple.
>
> I want to create a rule which says:
> If all subtasks of a parent task are completed, then the parent task
> can be completed too.
>
> I tried the code below, but it seems that I can not use "foreach" at
> LHS of a rule.
>
> (defrule BuildPlanForward
>     (depends-on (parent ?a) (children ?list))
>     (foreach ?c ?list  (available-part (name ?c)))
>     =>
>     (assert (available-part (name ?a)))
>     )
>
> How could I write such a rule in Jess?
>
> Thanks,
>
> --
> Levent Kent




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: Iteration over list

by Levent Kent :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I would do that. But the problem is I want to test if [there exists a fact of the form (available-part (name X)) for all X inside the list].
That's why the solution you offered would not work, since I just want to test instead of adding new facts.

Thanks for your response and I hope I could express myself clearer this time.

Best regards,

Levent





On Tue, Jul 28, 2009 at 4:27 PM, Nick Tinnemeier <nick@...> wrote:
Dear Levent,

You are using a function (foreach) at the LHS of a rule. See http://www.jessrules.com/FAQ.shtml#Q17 for an explanation on why this is not good practice.
Try putting the foreach loop on the RHS of the rule, and most likely things will work as expected.


(defrule BuildPlanForward
  (depends-on (parent ?a) (children ?list))
  =>
  (foreach ?c ?list (assert (available-part (name ?a))))

- Nick.


levent kent wrote:

Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
   (depends-on (parent ?a) (children ?list))
   (foreach ?c ?list  (available-part (name ?c)))
   =>
   (assert (available-part (name ?a)))
   )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent

Re: JESS: Iteration over list

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It would be easier to detect a depends-on where the available-part would be missing for one of its name list elements.

As it stands now, you'll need an identifier for depends-on so that the binding into the not (via ?x) is possible.

(defrule every-subtask
  (depends-on (id ?x)(parent ?a))
  (not (and (depends-on (id ?x)(name ? ?n ?))
            (not (available-part (name ?n)))))
   =>
  (assert (available-part (name ?a)))
)

-W


On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...> wrote:
Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
    (depends-on (parent ?a) (children ?list))
    (foreach ?c ?list  (available-part (name ?c)))
    =>
    (assert (available-part (name ?a)))
    )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent


Re: JESS: Iteration over list

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is the right solution; it could be simplified a little using the  
"forall" conditional element, which would make this closer to the  
spirit of the Levent's original:

(defrule every-subtask
   (depends-on (id ?x)(parent ?a))
   (forall (depends-on (id ?x)(name ? ?n ?))
           (available-part (name ?n)))
    =>
   (assert (available-part (name ?a)))
)




On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:

> It would be easier to detect a depends-on where the available-part  
> would be missing for one of its name list elements.
>
> As it stands now, you'll need an identifier for depends-on so that  
> the binding into the not (via ?x) is possible.
>
> (defrule every-subtask
>   (depends-on (id ?x)(parent ?a))
>   (not (and (depends-on (id ?x)(name ? ?n ?))
>             (not (available-part (name ?n)))))
>    =>
>   (assert (available-part (name ?a)))
> )
>
> -W
>
>
> On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...>  
> wrote:
> Hi  everybody,
>
> I am doing my masters thesis and have a problem with lists.
> It is actually very simple.
>
> I want to create a rule which says:
> If all subtasks of a parent task are completed, then the parent task  
> can be completed too.
>
> I tried the code below, but it seems that I can not use "foreach" at  
> LHS of a rule.
>
> (defrule BuildPlanForward
>     (depends-on (parent ?a) (children ?list))
>     (foreach ?c ?list  (available-part (name ?c)))
>     =>
>     (assert (available-part (name ?a)))
>     )
>
> How could I write such a rule in Jess?
>
> Thanks,
>
> --
> Levent Kent
>

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





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


JESS: strings and quoting

by jo-48 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi  everybody,

I am wrestling with strings in jess & java

Now everytime strings get trough a printout to file I get more and more escaped quotes and escaped backslashses,  like  ie

     "\"\\\". mystring ...

How can I avoid this trouble? I tries str-cat, implode$, nothing but somehow quoting still occurs... Utterly confused...

Thanks,

--
Joe


Re: JESS: Iteration over list

by Levent Kent :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks again, but I didn't get it. I don't have any slot named "id" or "name".
Idefined my templates as follows.

(deftemplate depends-on (slot parent) (multislot children))
(deftemplate available-part (slot name))

Here, depends-on relation specifies which parent task depends on the subtaks given in the multislot named "children".

To complete a "parent task", one should first complete the subtasks. I a task ?x is to be completed, the system adds (available-part (name ?x)) to the working memory. So, I need to check if all subtasks of a parent task ?p are "available-part" or not to insert (availabl-part (name ?p)) to WM.

I hope it is not difficult ot rewrite your query.

Thanks


On Tue, Jul 28, 2009 at 5:16 PM, Ernest Friedman-Hill <ejfried@...> wrote:
This is the right solution; it could be simplified a little using the "forall" conditional element, which would make this closer to the spirit of the Levent's original:


(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (forall (depends-on (id ?x)(name ? ?n ?))

         (available-part (name ?n)))
  =>
 (assert (available-part (name ?a)))
)




On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:

It would be easier to detect a depends-on where the available-part would be missing for one of its name list elements.

As it stands now, you'll need an identifier for depends-on so that the binding into the not (via ?x) is possible.

(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (not (and (depends-on (id ?x)(name ? ?n ?))
           (not (available-part (name ?n)))))
  =>
 (assert (available-part (name ?a)))
)

-W


On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...> wrote:
Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
   (depends-on (parent ?a) (children ?list))
   (foreach ?c ?list  (available-part (name ?c)))
   =>
   (assert (available-part (name ?a)))
   )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent


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






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent

Re: JESS: Iteration over list

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, where I have "name" in depends-on, that was meant to be your slot "children".

As for the id slot I added: I don't think it can be done without. It just should be a unique identifier.
It serves the same or similar purpose in Ernest's solution, to freeze the forall iteration to the children list elements of a *single* depends-on fact, i.e., the one matched in the initial CE.

-W

 

On Tue, Jul 28, 2009 at 5:31 PM, levent kent <thelevent@...> wrote:
Thanks again, but I didn't get it. I don't have any slot named "id" or "name".
Idefined my templates as follows.

(deftemplate depends-on (slot parent) (multislot children))
(deftemplate available-part (slot name))

Here, depends-on relation specifies which parent task depends on the subtaks given in the multislot named "children".

To complete a "parent task", one should first complete the subtasks. I a task ?x is to be completed, the system adds (available-part (name ?x)) to the working memory. So, I need to check if all subtasks of a parent task ?p are "available-part" or not to insert (availabl-part (name ?p)) to WM.

I hope it is not difficult ot rewrite your query.

Thanks



On Tue, Jul 28, 2009 at 5:16 PM, Ernest Friedman-Hill <ejfried@...> wrote:
This is the right solution; it could be simplified a little using the "forall" conditional element, which would make this closer to the spirit of the Levent's original:


(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (forall (depends-on (id ?x)(name ? ?n ?))

         (available-part (name ?n)))
  =>
 (assert (available-part (name ?a)))
)




On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:

It would be easier to detect a depends-on where the available-part would be missing for one of its name list elements.

As it stands now, you'll need an identifier for depends-on so that the binding into the not (via ?x) is possible.

(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (not (and (depends-on (id ?x)(name ? ?n ?))
           (not (available-part (name ?n)))))
  =>
 (assert (available-part (name ?a)))
)

-W


On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...> wrote:
Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
   (depends-on (parent ?a) (children ?list))
   (foreach ?c ?list  (available-part (name ?c)))
   =>
   (assert (available-part (name ?a)))
   )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent


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






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent


Re: JESS: strings and quoting

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How can we read your mind? I tried Tarot cards, a Crystal Ball and ESP, but somehow...

Kindly show an example of Jess or Java code, what it prints and what you expect it to do.

-W

On Tue, Jul 28, 2009 at 5:22 PM, jo <etaoinbe@...> wrote:

Hi  everybody,

I am wrestling with strings in jess & java

Now everytime strings get trough a printout to file I get more and more escaped quotes and escaped backslashses,  like  ie

     "\"\\\". mystring ...

How can I avoid this trouble? I tries str-cat, implode$, nothing but somehow quoting still occurs... Utterly confused...

Thanks,

--
Joe



Re: JESS: Iteration over list

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you can replace all occurrences of "id" with "parent",  
removing the redundant "parent" reference in the first fact.


On Jul 28, 2009, at 1:35 PM, Wolfgang Laun wrote:

> Sorry, where I have "name" in depends-on, that was meant to be your  
> slot "children".
>
> As for the id slot I added: I don't think it can be done without. It  
> just should be a unique identifier.
> It serves the same or similar purpose in Ernest's solution, to  
> freeze the forall iteration to the children list elements of a  
> *single* depends-on fact, i.e., the one matched in the initial CE.
>
> -W
>
>
>
> On Tue, Jul 28, 2009 at 5:31 PM, levent kent <thelevent@...>  
> wrote:
> Thanks again, but I didn't get it. I don't have any slot named "id"  
> or "name".
> Idefined my templates as follows.
>
> (deftemplate depends-on (slot parent) (multislot children))
> (deftemplate available-part (slot name))
>
> Here, depends-on relation specifies which parent task depends on the  
> subtaks given in the multislot named "children".
>
> To complete a "parent task", one should first complete the subtasks.  
> I a task ?x is to be completed, the system adds (available-part  
> (name ?x)) to the working memory. So, I need to check if all  
> subtasks of a parent task ?p are "available-part" or not to insert  
> (availabl-part (name ?p)) to WM.
>
> I hope it is not difficult ot rewrite your query.
>
> Thanks
>
>
>
> On Tue, Jul 28, 2009 at 5:16 PM, Ernest Friedman-Hill <ejfried@...
> > wrote:
> This is the right solution; it could be simplified a little using  
> the "forall" conditional element, which would make this closer to  
> the spirit of the Levent's original:
>
>
> (defrule every-subtask
>  (depends-on (id ?x)(parent ?a))
>  (forall (depends-on (id ?x)(name ? ?n ?))
>
>          (available-part (name ?n)))
>   =>
>  (assert (available-part (name ?a)))
> )
>
>
>
>
> On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:
>
> It would be easier to detect a depends-on where the available-part  
> would be missing for one of its name list elements.
>
> As it stands now, you'll need an identifier for depends-on so that  
> the binding into the not (via ?x) is possible.
>
> (defrule every-subtask
>  (depends-on (id ?x)(parent ?a))
>  (not (and (depends-on (id ?x)(name ? ?n ?))
>            (not (available-part (name ?n)))))
>   =>
>  (assert (available-part (name ?a)))
> )
>
> -W
>
>
> On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...>  
> wrote:
> Hi  everybody,
>
> I am doing my masters thesis and have a problem with lists.
> It is actually very simple.
>
> I want to create a rule which says:
> If all subtasks of a parent task are completed, then the parent task  
> can be completed too.
>
> I tried the code below, but it seems that I can not use "foreach" at  
> LHS of a rule.
>
> (defrule BuildPlanForward
>    (depends-on (parent ?a) (children ?list))
>    (foreach ?c ?list  (available-part (name ?c)))
>    =>
>    (assert (available-part (name ?a)))
>    )
>
> How could I write such a rule in Jess?
>
> Thanks,
>
> --
> Levent Kent
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            ejfried@...
> Livermore, CA 94550                             http://www.jessrules.com
>
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list
> (use your own address!) List problems? Notify owner-jess-users@...
> .
> --------------------------------------------------------------------
>
>
>
>
> --
> Levent Kent
>

---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


JESS: Debugging Jess

by Dresdner, Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it (will it) possible to Run/Debug JessML in the JessDE?
Thanks a lot,
Barry


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: strings and quoting

by jo-48 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Maybe I will find myself but this is my problem now:

(deffunction split-line (?line )
    (bind ?s (new String ?line ))
    (bind ?items (?s split  "[ ]+" ) )
    (return ?items)
)

Jess> (bind ?s (split-line "a b c"))
("a" "b" "c")
Jess> (bind ?t (implode$ ?s))
"\"a\" \"b\" \"c\""
Jess>

I do not want the quotes in ?t

tx
J




From: Wolfgang Laun <wolfgang.laun@...>
To: jess-users@...
Sent: Tuesday, July 28, 2009 7:39:47 PM
Subject: Re: JESS: strings and quoting

How can we read your mind? I tried Tarot cards, a Crystal Ball and ESP, but somehow...

Kindly show an example of Jess or Java code, what it prints and what you expect it to do.

-W

On Tue, Jul 28, 2009 at 5:22 PM, jo <etaoinbe@...> wrote:

Hi  everybody,

I am wrestling with strings in jess & java

Now everytime strings get trough a printout to file I get more and more escaped quotes and escaped backslashses,  like  ie

     "\"\\\". mystring ...

How can I avoid this trouble? I tries str-cat, implode$, nothing but somehow quoting still occurs... Utterly confused...

Thanks,

--
Joe




Re: JESS: Iteration over list

by Levent Kent :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for your help. I think this solves the problem:

(defrule propagate-back
 (forall (depends-on (parent ?x)(children ? ?n ?))
        (available-part (name ?n)))
 =>
 (assert (available-part (name ?x)))
)

The problem was that I did not know about the "forall" conditional element, which was introduced in the later than many other constructs.

Best regards,


On Tue, Jul 28, 2009 at 7:44 PM, Ernest Friedman-Hill <ejfried@...> wrote:
I think you can replace all occurrences of "id" with "parent", removing the redundant "parent" reference in the first fact.



On Jul 28, 2009, at 1:35 PM, Wolfgang Laun wrote:

Sorry, where I have "name" in depends-on, that was meant to be your slot "children".

As for the id slot I added: I don't think it can be done without. It just should be a unique identifier.
It serves the same or similar purpose in Ernest's solution, to freeze the forall iteration to the children list elements of a *single* depends-on fact, i.e., the one matched in the initial CE.

-W



On Tue, Jul 28, 2009 at 5:31 PM, levent kent <thelevent@...> wrote:
Thanks again, but I didn't get it. I don't have any slot named "id" or "name".
Idefined my templates as follows.

(deftemplate depends-on (slot parent) (multislot children))
(deftemplate available-part (slot name))

Here, depends-on relation specifies which parent task depends on the subtaks given in the multislot named "children".

To complete a "parent task", one should first complete the subtasks. I a task ?x is to be completed, the system adds (available-part (name ?x)) to the working memory. So, I need to check if all subtasks of a parent task ?p are "available-part" or not to insert (availabl-part (name ?p)) to WM.

I hope it is not difficult ot rewrite your query.

Thanks



On Tue, Jul 28, 2009 at 5:16 PM, Ernest Friedman-Hill <ejfried@...> wrote:
This is the right solution; it could be simplified a little using the "forall" conditional element, which would make this closer to the spirit of the Levent's original:


(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (forall (depends-on (id ?x)(name ? ?n ?))

        (available-part (name ?n)))
 =>
 (assert (available-part (name ?a)))
)




On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:

It would be easier to detect a depends-on where the available-part would be missing for one of its name list elements.

As it stands now, you'll need an identifier for depends-on so that the binding into the not (via ?x) is possible.

(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (not (and (depends-on (id ?x)(name ? ?n ?))
          (not (available-part (name ?n)))))
 =>
 (assert (available-part (name ?a)))
)

-W


On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...> wrote:
Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
  (depends-on (parent ?a) (children ?list))
  (foreach ?c ?list  (available-part (name ?c)))
  =>
  (assert (available-part (name ?a)))
  )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent


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






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent


---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent

Re: JESS: strings and quoting

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

(deffunction join ( ?list )
  (bind ?res "")
  (bind ?sep "")
  (foreach ?el ?list
     (bind ?res (str-cat ?res ?sep ?el))
     (bind ?sep " ")
  )
  (return ?res)
)

Use this instead of implode.
-W

On Wed, Jul 29, 2009 at 9:49 AM, jo <etaoinbe@...> wrote:
Maybe I will find myself but this is my problem now:

(deffunction split-line (?line )
    (bind ?s (new String ?line ))
    (bind ?items (?s split  "[ ]+" ) )
    (return ?items)
)

Jess> (bind ?s (split-line "a b c"))
("a" "b" "c")
Jess> (bind ?t (implode$ ?s))
"\"a\" \"b\" \"c\""
Jess>

I do not want the quotes in ?t

tx
J




From: Wolfgang Laun <wolfgang.laun@...>
To: jess-users@...
Sent: Tuesday, July 28, 2009 7:39:47 PM
Subject: Re: JESS: strings and quoting

How can we read your mind? I tried Tarot cards, a Crystal Ball and ESP, but somehow...

Kindly show an example of Jess or Java code, what it prints and what you expect it to do.

-W

On Tue, Jul 28, 2009 at 5:22 PM, jo <etaoinbe@...> wrote:

Hi  everybody,

I am wrestling with strings in jess & java

Now everytime strings get trough a printout to file I get more and more escaped quotes and escaped backslashses,  like  ie

     "\"\\\". mystring ...

How can I avoid this trouble? I tries str-cat, implode$, nothing but somehow quoting still occurs... Utterly confused...

Thanks,

--
Joe





Re: JESS: Iteration over list

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 29, 2009 at 10:48 AM, levent kent <thelevent@...> wrote:
Thanks for your help. I think this solves the problem:

(defrule propagate-back
 (forall (depends-on (parent ?x)(children ? ?n ?))
        (available-part (name ?n)))
 =>
 (assert (available-part (name ?x)))
)

This won't do as ?x isn't visible on the right hand side. Since forall would (potentially) match several depends-on facts a single variable cannot be used.

If the parent slot value is a unique identifier for depends-on, stick with Ernest's last proposal, i.e.,
(defrule propagate-back
 (parent ?x)
 (forall (depends-on (parent ?x)(children ? ?n ?))
        (available-part (name ?n)))
=>...

-W
 


The problem was that I did not know about the "forall" conditional element, which was introduced in the later than many other constructs.

Best regards,


On Tue, Jul 28, 2009 at 7:44 PM, Ernest Friedman-Hill <ejfried@...> wrote:
I think you can replace all occurrences of "id" with "parent", removing the redundant "parent" reference in the first fact.



On Jul 28, 2009, at 1:35 PM, Wolfgang Laun wrote:

Sorry, where I have "name" in depends-on, that was meant to be your slot "children".

As for the id slot I added: I don't think it can be done without. It just should be a unique identifier.
It serves the same or similar purpose in Ernest's solution, to freeze the forall iteration to the children list elements of a *single* depends-on fact, i.e., the one matched in the initial CE.

-W



On Tue, Jul 28, 2009 at 5:31 PM, levent kent <thelevent@...> wrote:
Thanks again, but I didn't get it. I don't have any slot named "id" or "name".
Idefined my templates as follows.

(deftemplate depends-on (slot parent) (multislot children))
(deftemplate available-part (slot name))

Here, depends-on relation specifies which parent task depends on the subtaks given in the multislot named "children".

To complete a "parent task", one should first complete the subtasks. I a task ?x is to be completed, the system adds (available-part (name ?x)) to the working memory. So, I need to check if all subtasks of a parent task ?p are "available-part" or not to insert (availabl-part (name ?p)) to WM.

I hope it is not difficult ot rewrite your query.

Thanks



On Tue, Jul 28, 2009 at 5:16 PM, Ernest Friedman-Hill <ejfried@...> wrote:
This is the right solution; it could be simplified a little using the "forall" conditional element, which would make this closer to the spirit of the Levent's original:


(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (forall (depends-on (id ?x)(name ? ?n ?))

        (available-part (name ?n)))
 =>
 (assert (available-part (name ?a)))
)




On Jul 28, 2009, at 10:53 AM, Wolfgang Laun wrote:

It would be easier to detect a depends-on where the available-part would be missing for one of its name list elements.

As it stands now, you'll need an identifier for depends-on so that the binding into the not (via ?x) is possible.

(defrule every-subtask
 (depends-on (id ?x)(parent ?a))
 (not (and (depends-on (id ?x)(name ? ?n ?))
          (not (available-part (name ?n)))))
 =>
 (assert (available-part (name ?a)))
)

-W


On Tue, Jul 28, 2009 at 2:47 PM, levent kent <thelevent@...> wrote:
Hi  everybody,

I am doing my masters thesis and have a problem with lists.
It is actually very simple.

I want to create a rule which says:
If all subtasks of a parent task are completed, then the parent task can be completed too.

I tried the code below, but it seems that I can not use "foreach" at LHS of a rule.

(defrule BuildPlanForward
  (depends-on (parent ?a) (children ?list))
  (foreach ?c ?list  (available-part (name ?c)))
  =>
  (assert (available-part (name ?a)))
  )

How could I write such a rule in Jess?

Thanks,

--
Levent Kent


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






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent


---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------




--
Levent Kent


Re: JESS: Debugging Jess

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A run configuration to let you run JessML directly would be easy to  
add, but source-level debugging would not. JessML is translated to  
Jess code a whole file at a time for execution.


On Jul 28, 2009, at 4:16 PM, Dresdner, Barry wrote:

> Is it (will it) possible to Run/Debug JessML in the JessDE?
> Thanks a lot,
> Barry
>

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





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: Debugging Jess

by Dresdner, Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the explanation.  Is the issue that there is currently no way
of mapping the executed line of the Jess Code to corresponding JessML
element?

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Wednesday, July 29, 2009 10:42 AM
To: jess-users
Subject: Re: JESS: Debugging Jess

A run configuration to let you run JessML directly would be easy to add,
but source-level debugging would not. JessML is translated to Jess code
a whole file at a time for execution.


On Jul 28, 2009, at 4:16 PM, Dresdner, Barry wrote:

> Is it (will it) possible to Run/Debug JessML in the JessDE?
> Thanks a lot,
> Barry
>

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





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list (use
your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: Debugging Jess

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 29, 2009, at 11:33 AM, Dresdner, Barry wrote:

> Thanks for the explanation.  Is the issue that there is currently no  
> way
> of mapping the executed line of the Jess Code to corresponding JessML
> element?
>


Yes, I guess that's right. In debug mode, the SAX parser would have to  
be updated to call Rete.recordFunction() to set the line number  
whenever it built a Funcall. Now that you  have drawn me out on this,  
it doesn't actually look that bad.

Is this something people would actually use? Running JessML code  
directly in a debugger, I mean?


> -----Original Message-----
> From: owner-jess-users@... [mailto:owner-jess-users@...]
> On Behalf Of Ernest Friedman-Hill
> Sent: Wednesday, July 29, 2009 10:42 AM
> To: jess-users
> Subject: Re: JESS: Debugging Jess
>
> A run configuration to let you run JessML directly would be easy to  
> add,
> but source-level debugging would not. JessML is translated to Jess  
> code
> a whole file at a time for execution.
>
>
> On Jul 28, 2009, at 4:16 PM, Dresdner, Barry wrote:
>
>> Is it (will it) possible to Run/Debug JessML in the JessDE?
>> Thanks a lot,
>> Barry
>>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            ejfried@...
> Livermore, CA 94550                             http://www.jessrules.com
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list (use
> your own address!) List problems? Notify owner-jess-users@....
> --------------------------------------------------------------------
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list
> (use your own address!) List problems? Notify owner-jess-users@...
> .
> --------------------------------------------------------------------

---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: Debugging Jess

by Dresdner, Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK, this is sounding better :-) We would definitely use it.  We will be
writing tools that will be generating only JessML.
Thanks again

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Wednesday, July 29, 2009 11:44 AM
To: jess-users
Subject: Re: JESS: Debugging Jess


On Jul 29, 2009, at 11:33 AM, Dresdner, Barry wrote:

> Thanks for the explanation.  Is the issue that there is currently no
> way of mapping the executed line of the Jess Code to corresponding
> JessML element?
>


Yes, I guess that's right. In debug mode, the SAX parser would have to
be updated to call Rete.recordFunction() to set the line number whenever
it built a Funcall. Now that you  have drawn me out on this, it doesn't
actually look that bad.

Is this something people would actually use? Running JessML code
directly in a debugger, I mean?


> -----Original Message-----
> From: owner-jess-users@... [mailto:owner-jess-users@...]
> On Behalf Of Ernest Friedman-Hill
> Sent: Wednesday, July 29, 2009 10:42 AM
> To: jess-users
> Subject: Re: JESS: Debugging Jess
>
> A run configuration to let you run JessML directly would be easy to
> add, but source-level debugging would not. JessML is translated to
> Jess code a whole file at a time for execution.
>
>
> On Jul 28, 2009, at 4:16 PM, Dresdner, Barry wrote:
>
>> Is it (will it) possible to Run/Debug JessML in the JessDE?
>> Thanks a lot,
>> Barry
>>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            ejfried@...
> Livermore, CA 94550
http://www.jessrules.com
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list (use

> your own address!) List problems? Notify owner-jess-users@....
> --------------------------------------------------------------------
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list (use

> your own address!) List problems? Notify owner-jess-users@... .
> --------------------------------------------------------------------

---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list (use
your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: Debugging Jess

by Dresdner, Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK, this is sounding better :-) We would definitely use it.  We will be
writing tools that will be generating only JessML.
Thanks again

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Wednesday, July 29, 2009 11:44 AM
To: jess-users
Subject: Re: JESS: Debugging Jess


On Jul 29, 2009, at 11:33 AM, Dresdner, Barry wrote:

> Thanks for the explanation.  Is the issue that there is currently no
> way of mapping the executed line of the Jess Code to corresponding
> JessML element?
>


Yes, I guess that's right. In debug mode, the SAX parser would have to
be updated to call Rete.recordFunction() to set the line number whenever
it built a Funcall. Now that you  have drawn me out on this, it doesn't
actually look that bad.

Is this something people would actually use? Running JessML code
directly in a debugger, I mean?


> -----Original Message-----
> From: owner-jess-users@... [mailto:owner-jess-users@...]
> On Behalf Of Ernest Friedman-Hill
> Sent: Wednesday, July 29, 2009 10:42 AM
> To: jess-users
> Subject: Re: JESS: Debugging Jess
>
> A run configuration to let you run JessML directly would be easy to
> add, but source-level debugging would not. JessML is translated to
> Jess code a whole file at a time for execution.
>
>
> On Jul 28, 2009, at 4:16 PM, Dresdner, Barry wrote:
>
>> Is it (will it) possible to Run/Debug JessML in the JessDE?
>> Thanks a lot,
>> Barry
>>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            ejfried@...
> Livermore, CA 94550
http://www.jessrules.com
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list (use

> your own address!) List problems? Notify owner-jess-users@....
> --------------------------------------------------------------------
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> you@...'
> in the BODY of a message to majordomo@..., NOT to the list (use

> your own address!) List problems? Notify owner-jess-users@... .
> --------------------------------------------------------------------

---------------------------------------------------------
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 you@...'
in the BODY of a message to majordomo@..., NOT to the list (use
your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------