Thanks Ernest Friedman again for the reply!

>If you use a pattern like

>(demandPool (demands $?first ?demand&:(eq (get-member ?demand type) "x") $?rest))

>then the particular demand that had type "x" is already bound to the
>variable ?demand and is available on the rule's RHS.
 
In above rule, if I want to get all the matching demands as list on RHS, how can I get them?
Right now, I only get first demand that's matched.
 
Thanks
Bhaskar


[EMAIL PROTECTED] wrote:
I think bhaskar yallala wrote:
>
> Secondly, In (demandPool (demands $?first ?demand&:(eq (get-member ?demand) "x") $?rest))
> what does it mean by $?first and $?rest? Does it mean it will iterate starting from first to the end?


$?first and $?rest are just multifields (i.e., variables that match 0
or more items in a list.) Something like

(shopping-cart $?a milk $?b)

matches whenever the shopping-care contains milk; $?a optionally
matches any items in the cart before the milk, and $?b matches any at
the end. I like to use $?first and $?rest but you can use any names
you like.

>
> Thirdy, in
> (demandPool (types ?t1 ?t2 $?more))
> what does it mean by patterns types ?t1 ?t2 does it mean it will
> match those patterns of types 1 2 or 2 1 or 1 3 etc? What does it
> mean by $?more! ? Does it mean 1 2 3 etc patterns?


?t1, ?t2, and $?more are, again, just variables. A multifield matches
zero or more items, and a plain variable matches exactly two, so this
pattern matches when there are two or more items in the list.


> Is there any documentation about $?more , $?first $?rest, $?length etc any where?

This kind of matching is covered (briefly) on pages 103-104 of "Jess
in Action."


>
> Fourthly,if I want to bind the matching demand/s how can I do that?
> Is it like
> (demandPool (demands $?first (bind ?matchedDemand (?demand&:(eq (get-member ?demand) "x") )$?rest))
>

If you use a pattern like

(demandPool (demands $?first ?demand&:(eq (get-member ?demand type) "x") $?rest))

then the particular demand that had type "x" is already bound to the
variable ?demand and is available on the rule's RHS.



> Thanks
> Bhaskar
>
> [EMAIL PROTECTED] wrote:
> I think bhaskar yallala wrote:
> >
> > class DeandPool{
> >
> > int[] types;
> >
> > Demand[] demands;
> >
> > }
>
>
> First of all, defclasses turn JavaBean properties -- not member
> variables -- into template slots. You'll need "int[] getTypes()" and
> "Demand[] getDemands()" (and perhaps the equivalent setter methods,
> too) before these will show up as slots.
> >
> > (defrule checkPool
> >
> > (demandPool (types $?types)(demands $?demands)(OBJECT ?demandPool))
> >
> >
> > I want to write rule where on LHS, fire rule only if type is > 2..
>
> "?type" (or ?types, you've written both) is a list, and so can't be
> compared to a number. If you want to compare the length of this list
> then you could write
>
> (demandPoo! l (types $?types&:(> (length$ ?types) 2)))
>
> Although the best way to do it is to write a pattern that matches only
> when there are two or more types, like
>
> (demandPool (types ?t1 ?t2 $?more))
>
> >
> > And also I want to write a rule where demand.type="x", then only fire.
>
> When this is true for at least one Demand object in the demands slot?
> You could write something like
>
> (demandPool (demands $?first ?demand&:(eq (get-member ?demand) "x") $?rest))
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Science and Engineering PSEs Phone: (925) 294-2154
> Sandia National Labs FAX: (925) 294-2234
> PO Box 969, MS 9012 [EMAIL PROTECTED]
> Livermore, CA 94550 http://herzberg.ca.sandia.gov
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
>
>
>
> ---------------------------------
> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages!



---------------------------------------------------------
Ernest Friedman-Hill
Science and Engineering PSEs Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own add! ress!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------



Thanks and regards,
Bhaskar

[EMAIL PROTECTED]
[EMAIL PROTECTED]


Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.

Reply via email to