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:[email protected]?subject=Unsubscribe