[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: list iteration for statement
From: "John Belmonte" <jvb () prairienet ! org>
Date: 2001-06-13 1:26:37
Message-ID: 001601c0f3a7$e40402d0$8402a8c0 () johndell
[Download RAW message or body]
ET wrote:
> In C? C always gets the raw arguments. And a vararg Lua function
> may still get the 'n' field. It's not redundant. Try
>
> print(getn{nil,0,nil})
I see your point there!
A few messages back you corrected my statement about the vm not knowing
about lists, but I should have said the vm doesn't know how to compute n
given an arbitrary table. That is what had to be added when I implemented
the list-for loop. As you say the standard library's implementation of getn
is arbitrary, and it may not be a good idea to contaminate the vm with it.
I'm not looking to tackle the list semantics of Lua, I think it's a can of
worms. With the list-for, I was just trying to make an convenient and fast
equivalent of the foreachi function, which covers at least a third of the
loops I write.
I did a simple timing comparison between the following two loops, in the
case where "n" is already defined, and sum is a local:
for i = 1, getn(t) do
sum = sum + t[i]
end
for v in t do
sum = sum + v
end
The list-for is about 20% faster when t is local, and 30% faster when t is
global.
-John
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic