Reverse a list

J. Landman Gay jacque at hyperactivesw.com
Mon Feb 16 23:12:59 CET 2015


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.
>
> Kind regards
>
> Bernd
>
>
>
> --
> View this message in context: http://runtime-revolution.278305.n4.nabble.com/Reverse-a-list-tp4688611p4688891.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> 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
>


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list