I've attached the code, it's in my normal class/namespace based style. It
doesn't feel very lispish/functional.

The code is quite ugly with a lot of catch throw statements due to the fact
that I want things to terminate right away if the query fails.

I use the below code to test with and as far as I can see everything checks
out.

Note how the query tree can be nested using *and* and *or*.

The elements in the root of the query tree form an implicit and as this is
the most useful default behavior.

It will not work on data that is more than two dimensional, this is
intentional as I don't expect to use it on anything else atm.

(setq *Tst '(("age" 35) "hej" ("items" "knife" "tent" "boots" "hook")
("name" "henrik") ("password" "yep")))
(setq *Tst2 '(("age" 15) "hej" ("items" "pen" "paper") ("name" "henrik")
("password" "yep1")))
(setq *Lst (list *Tst *Tst2))
(setq *Query '((and (eq "hej") (or (eq "two") (eqk "name" "henrik"))) (nin
"items" "pen")  (in "items" "boots" "tent") (rng "age" 25 40)))
(pretty (filter> '+Qlst *Query *Lst))



On Sun, Jun 26, 2011 at 7:36 PM, Henrik Sarvell <hsarv...@gmail.com> wrote:

> Thanks Alex.
>
> We'll see what I'll manage come up with.
>
>
>
> On Sun, Jun 26, 2011 at 2:07 PM, Alexander Burger <a...@software-lab.de>wrote:
>
>> Hi Henrik,
>>
>> > When it comes to examining arbitrary lists can Pilog be a good (as in
>> terse)
>> > and fast fit?
>>
>> I'm not really convinced. My opinion is that Prolog is good at only one
>> task: Search with backtracking.
>>
>> For simple pattern matches, direct Lisp code is usually simpler (and
>> faster). With 'member', 'assoc', 'find' or 'pick' for simple cases, and
>> 'match' in general.
>>
>>
>> > Take the following list for example: ("one" "two" ("items" "knife"
>> "tent"
>> > "hook" "boots") ("key1" "yes") ("key2" "no"))
>> >
>> > We want to know if all of the following are true or not:
>> > 1.) It contains "one".
>>
>>    (member "one" L)
>>   (match '(@A "one" @Z) L)
>>
>> Note that for match it is advisable to 'use' the variables, i.e.
>>
>>   (use (@A @Z)
>>      (match '(@A "one" @Z) L) )
>>
>> For simplicity I omit the 'use' in the following examples.
>>
>>
>> > 2.) It contains ("key1" "yes"), i.e. a member of the list is a in itself
>> a
>> > list with "key1" in the car and "yes" as the second element. If it makes
>>
>>    (member '("key1" "yes") L)
>>   (match '(@A ("key1" "yes") @C) L)
>>   (match '(@A ("key1" @B) @C) L)
>>
>>
>> > 3.) It contains a member list with "items" in the car and both "boots"
>> and
>> > "tent" in the cdr.
>>
>>       (and
>>         (match '(@A ("items" @B) @Z) L)
>>         (member "boots" @B)
>>         (member "tent" @B) )
>>
>>      (let? X (assoc "items" L)
>>         (and (member "boots" X) (member "tent" X)) )
>>
>>      (find
>>         '((L)
>>            (and
>>               (= "items" (car L))
>>               (member "boots" (cdr L))
>>               (member "tent" (cdr L)) ) )
>>         L )
>>
>>
>> > ((? "one") (? "key1" "yes") (? "items" "boots" "tent") (! "two"))
>> >
>> > The last ! there should mean that the list can not contain "two" which
>>
>> One of the (sub)clauses above could also contain something like
>>
>>   (not (member "two" X))
>>
>> Or you can do a deep search
>>
>>   (not (fish '((X) (= "two" X)) L))
>>
>> Cheers,
>> - Alex
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>

Attachment: qlst.l
Description: Binary data

Reply via email to