Re: Nested array comparisons

2013-03-25 Thread Alex Tweedly
On 25/03/2013 13:47, Richard Gaskin wrote: PS: Alex, I appreciate the code you post on this list, but why do you always post code with each line preceded by ">"? Makes it more difficult to strip out the ">" to run the code. Aaaah - the joys of "almost standards" in email :-( I get the te

Re: Nested array comparisons

2013-03-25 Thread Richard Gaskin
Alex Tweedly wrote: try it yourself if you want to see the details - but the bottom line is that the arrays have the same keys and contents, comparing the arrays gets that right, and comparing the arrayencode() of the arrays says (wrongly) that they differ. QED - you can't compare the arrayencod

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Ok thanks for testimg. That's very useful to know. I must say I'm curious to find out more about the peculiarities of arrays now. -- Kind regards, Mark Schonewille Economy-x-Talk Http://economy-x-talk.com Share the clipboard of your computer over a local network with Clipboard Link http://clip

Re: Nested array comparisons

2013-03-24 Thread Alex Tweedly
Sorry - the copy/paste of the result included some binary characters, so the email was incomplete try it yourself if you want to see the details - but the bottom line is that the arrays have the same keys and contents, comparing the arrays gets that right, and comparing the arrayencode()

Re: Nested array comparisons

2013-03-24 Thread Alex Tweedly
OK, let's just test it - focusing on the likelihood that key order matters Code: on mouseup local T1, T2 local tK, j constant K = 10 repeat with i = 1 to K put random(i) into t1[i] end repeat put the keys of T1 into tK repeat with i = K down to 1 put line i of

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Hi Dick, At the start of this thread, it was observed that comparison of arrays as suggested by the documentation may detect false positives. Keys of arrays are sorted when they are used by a function or a get or put command. The sort is not random, as I stated before. Therefore, the arrays

Re: Nested array comparisons

2013-03-24 Thread Richard Gaskin
Dick Kriesel wrote: > ArrayEncode encodes not only the keys and values we can see in the > array but also the hash keys we cannot see. The invisible hash keys > depend in part on the sequence in which the keys were added to the > array, so they may be different for two equal arrays, so the > enc

Re: Nested array comparisons

2013-03-24 Thread Dick Kriesel
On Mar 24, 2013, at 1:29 PM, Mark Schonewille wrote: > As you can conclude from > > "To compare two arrays, simply use the = operator directly on them rather > than encoding them first." > > the documenation, particularly with regard to arrays, is not always correct. Hi, Mark. Of course do

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Monte, I just thought it is a nice solution. In the way I used it in my example, I trust it sufficiently to even recommend it to others. -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.com/xtalkp

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Dick, As you can conclude from "To compare two arrays, simply use the = operator directly on them rather than encoding them first." the documenation, particularly with regard to arrays, is not always correct. Moreover, I would expect that computers return the same value when doing two equal

Re: Nested array comparisons

2013-03-24 Thread Monte Goulding
On 25/03/2013, at 7:25 AM, Dick Kriesel wrote: > The dictionary entry for arrayEncode says two equal arrays may have different > array encodings: > > "Note: Arrays in LiveCode are un-ordered. This means in particular that > encoding two arrays will not necessarily produce the same result, eve

Re: Nested array comparisons

2013-03-24 Thread Monte Goulding
On 25/03/2013, at 7:06 AM, Mark Schonewille wrote: > If you really need to know this, then you'll have to investigate this by > yourself. You can't doubt me without proving that I'm wrong, but if you prove > that I'm wrong then I'll be happy to be corrected and learn something. I'm not sure

Re: Nested array comparisons

2013-03-24 Thread Dick Kriesel
On Mar 24, 2013, at 1:02 PM, Monte Goulding wrote: > I know the list of keys is not random but there's no guarantee on the order > as far as I know and I'd want to do a significant amount of testing before I > assume two arrays created under different circumstances might return the keys > in t

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Monte, If you really need to know this, then you'll have to investigate this by yourself. You can't doubt me without proving that I'm wrong, but if you prove that I'm wrong then I'll be happy to be corrected and learn something. -- Best regards, Mark Schonewille Economy-x-Talk Consulting an

Re: Nested array comparisons

2013-03-24 Thread Monte Goulding
On 25/03/2013, at 6:55 AM, Mark Schonewille wrote: > If you use them in the same line of a script, both arrayEncode function will > treat arrays in the same way. The list of keys is not random. Where is this documented? Why does the same line or a different line make a difference? I know th

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
Monte, If you use them in the same line of a script, both arrayEncode function will treat arrays in the same way. The list of keys is not random. -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.c

Re: Nested array comparisons

2013-03-24 Thread Monte Goulding
On 25/03/2013, at 2:22 AM, Mark Schonewille wrote: > if arrayEncode(array1) is arrayEncode(array2) then > -- do whatever > end if Is there any guarantee that the arrayEncode format is consistent given two arrays with the same keys? We can't be positive the keys will return the keys in the

Re: Nested array comparisons

2013-03-24 Thread Mark Schonewille
David, You can do this with: if arrayEncode(array1) is arrayEncode(array2) then -- do whatever end if -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.com/xtalkprogrammer KvK: 50277553 Use Color

Re: Nested array comparisons

2013-03-24 Thread Robert Sneidar
I am curious what would happen if yo compare to arrays with different keys. I seem to remember something about array comparisons only comparing keys and not their values. I might have been dreaming after a bout with some bad pizza though... Bob On Mar 23, 2013, at 12:43 PM, David Beck wrote:

Re: Nested array comparisons

2013-03-23 Thread David Beck
Here is a function, in the mean time, that will do a deep comparison of arrays: function arraysAreEqual array1, array2 if array1 is not array2 then return false put the keys of array1 into theKeys repeat for each line thisKey in theKeys put 0 into numberOfArrays if array1[ th

Re: Nested array comparisons

2013-03-23 Thread Monte Goulding
On 24/03/2013, at 6:43 AM, David Beck wrote: > If one has two nested arrays, can you compare the two for equality by doing > > if deepArray_1 is deepArray_2 then > -- do whatever > end if > > It looks like this does not work. That is, you get false positives at times > when the two arrays a

Re: Nested array comparisons

2013-03-23 Thread Dick Kriesel
On Mar 23, 2013, at 12:43 PM, David Beck wrote: > > If one has two nested arrays, can you compare the two for equality by doing > > if deepArray_1 is deepArray_2 then > -- do whatever > end if > > It looks like this does not work. That is, you get false positives at times > when the two ar

Re: Nested array comparisons

2013-03-23 Thread dunbarx
d Beck To: use-livecode Sent: Sat, Mar 23, 2013 3:45 pm Subject: Nested array comparisons If one has two nested arrays, can you compare the two for equality by doing if deepArray_1 is deepArray_2 then -- do whatever end if It looks like this does not work. That is, you get false positive

Nested array comparisons

2013-03-23 Thread David Beck
If one has two nested arrays, can you compare the two for equality by doing if deepArray_1 is deepArray_2 then -- do whatever end if It looks like this does not work. That is, you get false positives at times when the two arrays are in fact not equal. Can not find documentation to determine