Reverse a list

Mike Bonner bonnmike at gmail.com
Mon Feb 9 14:16:24 EST 2015


Thanks!  Yep, had figured out that I didn't need to worry about what sCount
was as long as it was lower each time.  Not sure why my noggin was so
insistent on doing it the other way, but.. /shrug

On Mon, Feb 9, 2015 at 12:10 PM, Geoff Canyon <gcanyon at gmail.com> wrote:

> A quick check and this works:
>
> local sCount
>
> function getCount
>    subtract 1 from sCount
>    return sCount
> end getCount
>
> on mouseUp
>    sort lines of fld 1 numeric by getCount()
> end mouseUp
>
> You don't need to have sCount start at the number of lines of the text to
> be sorted. It can start at 0 and go down from there, so you save the time
> of parsing the list to get the number of lines.
>
> Further, you don't need to initialize sCount ever, unless you plan to sort
> many billions of lines.
>
>
> On Sun, Feb 8, 2015 at 4:09 PM, Mike Bonner <bonnmike at gmail.com> wrote:
>
> > Just curious.. How does this compare?
> >
> > local scount
> > on mouseUp
> >    put the number of lines in field 1 + 1 into scount
> >    sort lines of field 1 by getCount()
> > end mouseUp
> >
> > function getCount
> >    subtract 1 from sCount
> >    return sCount
> > end getCount
> >
> > On Sun, Feb 8, 2015 at 2:52 PM, J. Landman Gay <jacque at hyperactivesw.com
> >
> > wrote:
> >
> > > Just tinkering around on a lazy Sunday, and I thought I'd come up with
> a
> > > neat way to reverse a list without using the traditional clunky method:
> > >
> > > function reverseSort pList
> > >   repeat for each line l in pList
> > >     put l & cr before tList
> > >   end repeat
> > >   return tList
> > > end reverseSort
> > >
> > > One of the best things I learned from a past LC converence came from
> > Jerry
> > > Daniels who said "let the engine do it." It's almost always faster and
> > more
> > > efficient. With that in mind I wrote this:
> > >
> > > 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
> > >
> > > function reverseSort pTxt
> > >   subtract 1 from sNum
> > >   return sNum && pTxt
> > > end reverseSort
> > >
> > > Works great and I was proud. Then I did some timing tests and found out
> > > the two methods are very close to equivalent in timing, and on long
> > lists,
> > > the first way is actually faster.
> > >
> > > So much for improving on LC's text chunking speed. Pah.
> > >
> > > --
> > > Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> > > HyperActive Software           |     http://www.hyperactivesw.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
> > >
> > _______________________________________________
> > 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