On Thu, 24 Sep 1998, Ernest Friedman-Hill wrote:
> > 1) Why must all "list" facts be ordered? It would be nice to assert
> > something like (shopping-list bread milk paper-towels), and then have this
> > fact match a (shopping-list milk bread paper-towels) pattern in some rule.
> > I guess you have to use a multislot in a deftemplate to implement a true
> > set, but you still have to do some pretty scary stuff in your pattern
> > matching.
>
> This is a reasonable question - the answer is efficiency. Jess can
> check specific positions in an ordered fact in time N, where N is the
> number of items. Checking them in any permutation would require at
> least time N! (N factorial) (but this would require lots of memory - a
> less storage-intensive method would work in time N^2) Often the order
> conveys meaning.
Assuming that the elements of the list are sortable, you can use qsort to
make the comparison in O(n log n). If the list is strings or numbers you
can use radix sort to make the comparison in O(n).
> You could write a deffunction or userfunction called
> contains-in-some-order to be used like this:
>
> (defrule example-1
> (shopping-list $?groceries)
> (test (contains-in-some-order $?groceries milk bread paper-towels))
> =>
But, it seems like a substantial undercurrent in the discussion here
involving the need for Jess to support various collection
classes (e.g. List vs. Bag vs. Set).
Jess users could do this repeatedly in an ad hoc application specific
manner, but an efficient set of generic rete compatible collections and operations
might be very helpful.
-Alex-
___________________________________________________________________
S. Alexander Jacobson i2x Media
1-212-697-0184 voice 1-212-697-1427 fax
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------