I would not use this rule provided I understood the problem correctly as:
"Find all facts foo where the length of foo.my-list equals the value of slot
foo.desired."

The proposed solution does not compare a length with foo.desired, and
binding of a multislot vaue should use a variable starting with $?.

I think the solution should be written as:

(deftemplate foo (multislot my-list)(slot desired (default 0)))

(defrule lok
  ?mf <- (foo (my-list $?list)(desired ?len &:(= (length$ $?list) ?len)))
=>
  (printout t ?mf " list " $?list " length " ?l crlf)
)

(deffacts facts
   (foo )
   (foo (my-list x y)(desired 2))
   (foo (my-list a b c)(desired 2))
)

(reset)
(facts)
(run)

kr
Wolfgang





On 2/19/08, Peter Lin <[EMAIL PROTECTED]> wrote:
>
>
> I believe you need to use
>
> (length$ <multifield-expression>)
>
> and then do a test to compare the two lengths. so the rule might look like
> this
>
> (defrule myrule
>     (foo
>         (my-list ?list1)
>     )
>     (foo
>         (my-list ?list2)
>     )
>    (test (eq (length$ ?list1) (length$ ?list2) ) )
> =>
>   (printout t "the lists have the same length)
> )
>
> that's how I've done it in the past. there might be an easier way.
>
> On Feb 19, 2008 4:04 PM, Hal Hildebrand <[EMAIL PROTECTED]> wrote:
>
> > I've been struggling with trying to formulate a LHS which tries to
> > match the length of one of the fact's multislots with another slot.
> > For example:
> >
> > (deftemplate foo (multislot my-list) (slot desired))
> >
> > I've tried the following:
> >
> > (foo (my-list ?my-list) (desired = (length$ ?my-list))
> >
> > (foo { desired == (length$ my-list) } )
> >
> > (foo  (my-list ?my-list { desired == (length$ ?my-list) } )
> >
> >
> > And even though desired is 0 and the length of the list is 0, the rule
> > simply won't fire.  Obviously, I'm missing something....
> >
> > --------------------------------------------------------------------
> > 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]
> > --------------------------------------------------------------------
> >
> >
>

Reply via email to