Here's an other way around based on swapping elements:

on revert theList
  nb = theList.count()
  
  repeat with i = 1 to nb/2
    tmp = theList[i]
    theList[i] = theList[nb+1-i]
    theList[nb+1-i] = tmp
  end repeat
end

This one using just one list: memory economy and is faster than colin's (for
a list of 10 elements, Colin's algorithm is doing 20 operations, mine's
doing only 15).

Your choice depends on the size of your list. For a big list, you should use
an optimized way.

regards,

Laurent

> -----Original Message-----
> From: Tab Julius [mailto:[EMAIL PROTECTED]]
> Sent: 8 f�vrier, 2002 10:21
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: <lingo-l> turning a list back to front
> 
> 
> 
> Hmmm... there are a couple of ways.
> 
> Here's one which involves inserting before the first element:
> 
> srcList =[1, 2, 3, 4, 5, 6]
> revList =[]
> repeat with thisEntry in srcList
>    addAt(revList, 1, thisEntry)
> end repeat
> 
> 
> Another is counting backward and adding in, but the above one 
> should do you 
> just fine.
> 
> - Tab
> 
> 
> 
> At 03:15 PM 2/8/02 +0100, Heike Schmidt wrote:
> >hello everyone,
> >
> >i'm a relative newbie to this list, so please dont get mad 
> if this seems a
> >bit pedestrian.
> >
> >here's my question:
> >is there a simpler way of turning a list back to front than 
> something like
> >this (the first value needs to be the last and vice versa)? 
> is there some
> >sort of "swop around" command that i just haven't found yet?
> >list = [1, 2, 3, 4, 5, 6]
> >oldlist = duplicate(list)
> >newlist = []
> >counter1 = list.count
> >
> >repeat with counter2=1 to list.count
> >newlist[counter2] = oldlist[counter1]
> >counter1 = counter1 - 1
> >end repeat
> >
> >
> >thank you very much,
> >heike .-)
> >
> >------------------------------------------------------------
> >
> >   heike schmidt
> >
> >   gekko mbh
> >   rathausallee 10
> >   53757 sankt augustin
> >   germany
> >
> >   fon 02241 - 944 97 39
> >   fax 02241 - 94497 33
> >   web www.gekko.de
> >
> >[To remove yourself from this list, or to change to digest 
> mode, go to 
> >http://www.penworks.com/lingo-l.cgi  To post messages to the 
> list, email 
> >[EMAIL PROTECTED]  (Problems, email 
> [EMAIL PROTECTED]). Lingo-L 
> >is for learning and helping with programming Lingo.  Thanks!]
> 
> [To remove yourself from this list, or to change to digest 
> mode, go to http://www.penworks.com/lingo-l.cgi  To post 
> messages to the list, email [EMAIL PROTECTED]  (Problems, 
> email [EMAIL PROTECTED]). Lingo-L is for learning and 
> helping with programming Lingo.  Thanks!]
> 
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to