Counting problem
Jacques Hausser
jacques.hausser at unil.ch
Sat May 25 04:44:18 EDT 2013
Craig,
A way to have the second script working correctly (sum on the counter array = 10) is to declare and fill the counter explicitly before using it; my version:
on mouseup
put "a,b,c,d,e,f,g,h,i,j" into temp
repeat with i = 1 to 10
put 0 into tcount[item i of temp]
end repeat
repeat 10
add 1 to tcount[any item of temp]
end repeat
put "" into fld "F1"
put 0 into tSum
repeat with i = 1 to 10
put item i of temp & " : " & tcount[item i of temp] & return after fld "F1"
add tcount[item i of temp] to tSum
end repeat
put return & "Sum = " & tSum after fld "F1"
end mouseUp
the sum is always 10 - if you want to go back to craziness, just comment out the first loop. Sums between 6 and 17 in my trials.
I also noticed that the automatic indent doesn't work correctly for the "repeat 10" loop - perhaps an indication that the interpreter doesn't understand exactly what we mean…
For Alex: I didn't observe the correcting effect of adding "put counter["b"] into tJunk" to the loop (OS 10.8.3, either with 6.0.1 or 5.5.4). The result was as bad as without the command.
A very intriguing bug anyway ! I filled a bug report, # 10925 (giving credit to Craig for his amazing discovery)
Jacques
Le 25 mai 2013 à 04:26, dunbarx at aol.com a écrit :
> Alex.
>
>
> I am the kind of guy that is happy to solve a problem without understanding it. But this one is, er, bugging me.
>
>
> Craig
>
>
>
> -----Original Message-----
> From: Alex Tweedly <alex at tweedly.net>
> To: use-livecode <use-livecode at lists.runrev.com>
> Sent: Fri, May 24, 2013 7:11 pm
> Subject: Re: Counting problem
>
>
> I see the same problem on both 5.5.3 and 6.0.1 - but testing in the
> message box.
>
> Oddly, I happened to notice that if I change the script to be
>
> put "a,b,c,d,e,f,g,h,i,j" into temp
> repeat 10
> add 1 to counter[any item of temp]
> put counter["b"] into tJunk -- i.e. I add a single useless line
> !!
> end repeat
>
>
>
> it works just fine every time.
> Don't know if that helps you or makes it worse :-)
>
> -- Alex.
>
> On 24/05/2013 22:56, dunbarx at aol.com wrote:
>> I know I am going to feel like a dope, but why does the first script always
>> properly give ten counts in the array variable "counter", but the second can
>> give anywhere from five to sixteen, and maybe others?
>>
>>
>>
>> on mouseUp
>> put "a,b,c,d,e,f,g,h,i,j" into temp
>> repeat 10
>> get any item of temp --always gives ten
>> add 1 to counter[it]
>> end repeat
>> end mouseUp
>>
>>
>> on mouseup
>> put "a,b,c,d,e,f,g,h,i,j" into temp
>> repeat 10
>> add 1 to counter[any item of temp]
>> end repeat
>> end mouseUp
>>
>>
>>
>>
>> I have deconstructed the problem line by watching the array in the debugger on
>> the sly after each iteration. It goes crazy, sometimes the count of a particular
>> char going DOWN.
>>
>>
>> Craig Newman
More information about the use-livecode
mailing list