lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jan 08, 2004 at 01:38:38PM -0800, Joe Myers wrote:
> Edgar's posting was a very interesting read.
> 
> However, if you replace
>      for idx,word2 in pairs(words) do -- loop foo
> 
> with
>      for idx,word2 in ipairs(words) do -- loop foo
> 
> it will become delightfully perky. This takes advantage that you're
> deleting words in the same order as their occurance, of course.
> 
> Joe
> 

Oh yeah. It becomes quite perky.  Because it isn't actually deleting
anything after the first iteration.  Add a debug print statement right
where the entry is set to nil and watch only the first word in the entire
list get deleted.  ipairs stops iteration after the first non-continuous
integer index after 0.  Once you set 1 to nil, there is a gap between 0
and 2.  The loop never runs beyond 0.

:)

scott

-- 
------------------------------------------------------------------------
scott jacobs                                   scott+lua@escherichia.net
------------------------------------------------------------------------