[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: list iteration for statement
- From: "Eric Ries" <eries@...>
- Date: Thu, 26 Apr 2001 10:19:43 -0400
Perhaps this is too kludgy, but we could always add
for val in list do
X
end
as syntactic sugar for
foreachi( list, function(i,val) X end )
It would make reading the code for that functionality cleaner, so it gets my
vote.
Eric
> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of John Belmonte
> Sent: Thursday, April 26, 2001 6:07 AM
> To: Multiple recipients of list
> Subject: Re: list iteration for statement
>
>
> Philippe Lhoste wrote:
> > Sorry if I don't answer correctly to your request, but I believe Lua
> already
> > have a mechanism for this.
> >
> > foreach (table, func)
> > foreachi (table, func)
>
> Sorry, I should have addressed these library functions in my
> post. Well, if
> foreach() is so great, why do we have a special for construct to
> do the same
> thing? Remember that the for command was created after these functions
> already existed. I'll bet that since for loops were introduced
> as a way to
> iterate tables, most of us don't use foreach() anymore. Having to create
> function objects can sometimes make code hard to follow. So
> since there is
> a form of for matching foreach(), why not foreachi() too?
>
> For comparison, here is my example again using foreachi. It's not bad in
> the case of a one-statement function, but for larger functions it becomes
> less readable that using a for construct.
>
> foreachi(list, function(i, val) print(val) end)
>
>
> -John
>