Re: Ordered Lists
Thomas Russ <[email protected]> Mon, 26 Nov 2007 10:57:47 -0800
| Newsgroups | gmane.comp.ai.powerloom |
|---|---|
| Message-ID | <[email protected]> |
On Nov 26, 2007, at 9:28 AM, Jeremy Leibs wrote:
> Are there any relations or functions implemented within powerloom yet
> that allow us to actually work with ordered lists?
Not too much is currently available.
> A list created using listof is specified to be "ordered," but I can't
> find any way to make use of this ordering (or even the fact that it's
> a list for that matter). Is there a way to at least define some
> simple list primitives such as first-of, rest-of, and append?
There is the general-purpose matching machinery, which can be used to
extract specific elements as long as you know at query creation time
the length of the list. For example, you can get the first two
elements of a 4-element list by
(retrieve all (exists (?x ?y) (= (listof ?first ?second ?x ?y)
(listof 1 2 3 4))))
There is 1 solution:
#1: ?FIRST=1, ?SECOND=2
This works with general functions and relations as well:
(defrelation places (?x (?y LIST)))
(assert (places 1st-race (listof sea-biscuit jenny on-the-money
limper)))
(assert (places 2nd-race (listof un deux trois quatre)))
(retrieve all (exists (?x ?y ?list)
(and (places ?race ?list)
(= (listof ?first ?second ?x ?y) ?list))))
There are 2 solutions:
#1: ?RACE=2ND-RACE, ?FIRST=UN, ?SECOND=DEUX
#2: ?RACE=1ST-RACE, ?FIRST=SEA-BISCUIT, ?SECOND=JENNY
This doesn't have the full flexibility you ask for. To do that, one
would need to provide specialist support for the reasoning. That
wouldn't be too hard to do, but it would take a little bit of work to
make sure it was done robustly. The basic primitives that I see
would be:
append list1 list2 list1+2
nth-element list n element
How important is the rest-of functionality?