Fun (was Re: Cubist's first bug report)

dsc at swcp.com dsc at swcp.com
Sun Jun 5 16:14:54 EDT 2016


on mouseUp
   put "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16" into myVar
   repeat 1000
      add zero to any item of myVar
   end repeat
   put  myVar
end mouseUp

> On Jun 5, 2016, at 2:06 PM, dsc at swcp.com wrote:
> 
> Just for fun:
> 
> on mouseUp
>   put LF into newLine
>   put 0 into sRandomCount
>   put "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16" into myVar
>   repeat 100
>      add zero to any item of myVar
>      put myVar & newLine after myTempList
>   end repeat
>   put  sum(myVar) & newLine & myTempList
> end mouseUp
> 
> 
> 
>> On Jun 5, 2016, at 1:15 PM, dsc at swcp.com wrote:
>> 
>> Here's a script (derived from Mark's) that illustrates the double call:
>> 
>> local sRandomCount
>> 
>> on mouseUp
>> 	put LF into newLine
>> 	put 0 into sRandomCount
>> 	put "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" into myVar
>> 	repeat 100
>> 		add 1 to item myrandom(16) of myVar
>> 		put myVar & newLine after myTempList
>> 	end repeat
>> 	put sRandomCount & tab & sum(myVar) & newLine & myTempList
>> end mouseUp
>> 
>> function myRandom n
>> 	add 1 to sRandomCount
>> 	return random(n)
>> end myRandom
>> 
>> 
>> 
>> 
>>> On Jun 5, 2016, at 12:42 PM, Dar Scott <dsc at swcp.com> wrote:
>>> 
>>> Very nice and clean example code.  
>>> 
>>> Also, as you hinted, this does have the problem:
>>> 	add 1 to item random(16) of myVar
>>> 
>>> I infer from this that the problem is very likely not in how 'any' counts items.  
>>> 
>>> This also applies to subtract and multiply.  I suspect that random(16) is being evaluated twice based on a first glance at the pattern.  Because of that, my guess is that this bug will not cause a crash.  
>>> 
>>> The problem also occurs when I use my own random function.  
>>> 
>>> it looks as though this...
>>> 	add 1 to any item of x
>>> ... is being evaluated as...
>>> 	put 1 + any item of x into any item of x
>>> ... which is incorrect.
>>> 
>>> Perhaps that is just the info needed for a quick fix.  
>>> 
>>> This also will show up for any function with side effects built-in or not, so this is a far ranging bug and it should be pushed up in priority.  
>>> 
>>> Dar
>>> 
>>> 
>>>> On Jun 5, 2016, at 8:48 AM, Mark Schonewille <m.schonewille at economy-x-talk.com> wrote:
>>>> 
>>>> Hi Quentin,
>>>> 
>>>> I see the same results, when I try your code. However, if I first store the random value and add 1 to an item in the string in the next line in the script, it works correctly. Apparently, the random function and the add command are incompatible.
>>>> 
>>>> on mouseUp
>>>> put "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" into myVar
>>>> repeat 100
>>>>   put random(16) into myRandom
>>>>   add 1 to item myRandom of myVar
>>>>   put myVar & cr after myTempList
>>>> end repeat
>>>> put sum(myVar) & cr & myTempList
>>>> end mouseUp
>>>> 
>>>> Kind regards,
>>>> 
>>>> Mark Schonewille
>>>> http://economy-x-talk.com
>>>> https://www.facebook.com/marksch
>>>> 
>>>> Buy the most extensive book on the
>>>> LiveCode language:
>>>> http://livecodebeginner.economy-x-talk.com
>>>> 
>>>> Op 05-Jun-16 om 16:12 schreef Quentin Long:
>>>>> Code which exhibits the bug:
>>>>> 
>>>>> on mouseUp
>>>>> put "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" into Fred
>>>>> repeat 100 times
>>>>>   add 1 to any item of Fred
>>>>>   put Fred into line (1 + the number of lines in fld "testbed") of fld "testbed"
>>>>> end repeat
>>>>> put sum (Fred) into line (1 + the number of lines in fld "testbed") of fld "testbed"
>>>>> end mouseUp
>>>>> 
>>>>> This handler *should* end up generating a 16-item string of integers which sum to exactly 100. What it *actually does* end up generating, is a 16-item string of integers whose sum may or may not fall somewhere within the range 80-120. Not sure what the hell is going on here, but I am not at all happy about it. Perhaps other people might like to try this code on their systems, and see if it works as intended for them?
>>>>> 
>>>>> http://quality.livecode.com/show_bug.cgi?id=17795
>>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> 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
>>> 
>>> 
>>> _______________________________________________
>>> 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
>> 
>> _______________________________________________
>> 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
> 
> _______________________________________________
> 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