filter?
Pete
pete at mollysrevenge.com
Thu Jun 23 13:23:22 EDT 2011
Now I can add "symmetric difference" to my extremely small vocabulary of set
theory terms! Largely academic at this point but there is a variation to the
array solution that Jacque and I offered which does it all in one repeat
loop:
put tlist1 & cr & tlist2 into tlist3
repeat with x=1 to the number of lines in tlist3
if line x of tlist3 is among the keys of tarray then
delete variable tarray[line x of tlist3]
else
put true into tarray[line x of tlist3]
end if
end repeat
At the end of the repeat, the keys of tarray will be the unique values. I
have no idea if substituting the if statement for an extra repeat loop makes
it more efficient.
Pete
Molly's Revenge <http://www.mollysrevenge.com>
On Thu, Jun 23, 2011 at 3:40 AM, Dick Kriesel <dick.kriesel at mail.com> wrote:
>
> On Jun 22, 2011, at 10:58 PM, Pete wrote:
>
> > I may be wrong, but I don't think intersect solves the problem. If I
> > understand the dictionary correctly, this will remove all the t1 keys
> that
> > do NOT match t2 keys so it does the opposite of what is needed.
>
> Thanks, Pete. I misunderstood the OP.
>
> He wants the symmetric difference.
> <http://en.wikipedia.org/wiki/Symmetric_difference>
>
> Here's a way:
>
>
> function symmetricDifferenceOfLists t1, t2
> split t1 by cr and tab
> split t2 by cr and tab
> return the keys of symmeticDifferenceOfArrays( t1, t2 )
> end symmetricDifferenceOfLists
>
> function symmeticDifferenceOfArrays p1, p2
> local tResult
> put differenceOfArrays( p1, p2 ) into tResult
> union tResult with differenceOfArrays( p2, p1 )
> return tResult
> end symmeticDifferenceOfArrays
>
> function differenceOfArrays t1, p1
> repeat for each key tKey in p1
> delete variable t1[ tKey ]
> end repeat
> return t1
> end differenceOfArrays
>
>
> In comparison, Jacque's code is looking lean.
>
> -- Dick
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
More information about the use-livecode
mailing list