Re: Pilog and list examination
Hi Henrik, 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 haven't investigated it too deeply yet, but perhaps these catch/throw constructs can be avoided: 'for' can be terminated at any time using the 'T' or 'NIL' clauses (same as in 'loop' and 'do'). Also, I'm not sure if looping over the data with 'for' is necessary at all. Direcly using functions with built-in looping, like 'member' and 'find', and also 'match', is probably faster. The whole issue looks to me as a typical application of nested 'match' calls (i.e. matching on partial expressions bound to pattern variables by previous matches). Just 2 cent at the moment ;-) Cheers, - Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Pilog and list examination
I have attached version two which is modeled after your advice, much smaller and more elegant. The question is, is it faster? I will have to test that tomorrow. On Mon, Jun 27, 2011 at 1:49 PM, Alexander Burger a...@software-lab.dewrote: Hi Henrik, 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 haven't investigated it too deeply yet, but perhaps these catch/throw constructs can be avoided: 'for' can be terminated at any time using the 'T' or 'NIL' clauses (same as in 'loop' and 'do'). Also, I'm not sure if looping over the data with 'for' is necessary at all. Direcly using functions with built-in looping, like 'member' and 'find', and also 'match', is probably faster. The whole issue looks to me as a typical application of nested 'match' calls (i.e. matching on partial expressions bound to pattern variables by previous matches). Just 2 cent at the moment ;-) Cheers, - Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe qlst.l Description: Binary data
Re: Pilog and list examination
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.dewrote: 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
Pilog and list examination
When it comes to examining arbitrary lists can Pilog be a good (as in terse) and fast fit? 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. 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 anything easier it can be assumed that this member will never have more than two elements. 3.) It contains a member list with items in the car and both boots and tent in the cdr. The only alternative to Pilog the way I see it is to create some kind of simple DSL that will work something like this algo-wise: 1.) Examine each element against the criteria list/tree. 2.) When a condition matches on an examined element we remove that criteria from the criteria list/tree. 3.) If the criteria list/tree is empty we catch T. 4.) If we reach the end of the examined list and we still have something in the criteria list we return NIL. An input/DSL to this engine could perhaps look something like this: ((? one) (? key1 yes) (? items boots tent) (! two)) The last ! there should mean that the list can not contain two which somehow needs to be treated as a normal positive search whose result is inverted with catch NIL perhaps. Any thoughts?