Reverse a list

BNig bernd.niggemann at
Mon Feb 16 18:04:40 EST 2015

Hi Jacque,

J. Landman Gay wrote
> This is getting to be just too much fun. I think Geoff was right, we 
> don't need to initialize sNum because we don't care if we go into 
> negative territory. And since the handler isn't actually using the value 
> of the line, we can omit passing it by removing "each". So it could be 
> even shorter/faster this way:
> local sNum
> function reverseText @pList
>     sort lines of pList numeric by reverseSort()
>     return pList
> end reverseText
> private function reverseSort
>     subtract 1 from sNum
>     return sNum
> end reverseSort
> I'm not sure the private declaration is necessary, but it won't hurt. My 
> thinking is that the engine only looks for a private function in the 
> current script, but it also looks in the current script first when the 
> function isn't private. If the function is there, it seems that the 
> speed would be the same in either case. The engine would stop looking at 
> the same place.
> Passing the list with @ is a good addition.
> Then there is Alex's version which is a different animal.
> On 2/16/2015 12:58 PM, BNig wrote:
>> Hi Peter,
>> you also might want to check your reverse algorithm on 7.x.x
>> in my testing Jacque's initial post with little tweaks is as fast as your
>> code and faster on 7.x.x (tested on 7.0.2 rc2) In my testing it took only
>> 60% of the time compared to yours on 7.x.x
>> Of course Alex Tweedly's ingenious inverse code leaves everything in the
>> dust, except on 7.x.x.
>> ----------------------------------------------------------------------
>> on mouseUp
>>     put field 1 into tData
>>     put the milliseconds into t
>>     get reverseText (tData)
>>     put the milliseconds - t into field "fRes"
>>     put it into field 1
>> end mouseUp
>> local sNum
>> function reverseText @pList
>>     put the number of lines in pList into sNum
>>     sort lines of pList numeric by reverseSort(each)
>>     return pList
>> end reverseText
>>   private function reverseSort
>>     subtract 1 from sNum
>>     return sNum
>> end reverseSort
>> --------------------------------------------------------
>> private and @ help when the line count is high.

funny, nobody likes "private" 

It save up to 20 % all else equal.

On about 44000 lines 5 items on each line

with private 86 ms, without 106 ms LC 6.7.2

with private roughly 180 ms, without 200 ms on LC 7.0.2 rc2 (times vary much
more on LC 7.0.2 rc2 than on LC 6.7.2

Kind regards

View this message in context:
Sent from the Revolution - User mailing list archive at

More information about the Use-livecode mailing list