[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Abolishing the numeric-for
- From: George Petsagourakis <petsagouris@...>
- Date: Wed, 26 May 2010 18:39:00 +0000 (UTC)
Ok... I think I can generate some noise too.
t = {
"apples",
"bananas",
"apricots",
apples_eaten = 4,
bananas_eaten = 5,
apricots_eaten =0
}
-- this traverses only the numeric indexes
-- makes use of one invisible implied default local variable '__i'
for t do
print(__i.." = "..t[__i])
end
-- should output:
-- 1 = apples
-- 2 = bananas
-- 3 = apricots
-- this traverses only non numeric indexes
-- makes use of two invisible implied default local variables '__i' and '__v'
foreach t do
print(__i.." = "..__v)
end
-- should output:
-- apples_eaten = 4
-- bananas_eaten = 5
-- apricots_eaten = 0
-- this traverses any indexes
-- makes use of one invisible implied default local variable '__i'
forany t do
print(__i.." = "..t[__i])
end
-- should output:
-- 1 = apples
-- 2 = bananas
-- 3 = apricots
-- apples_eaten = 4
-- bananas_eaten = 5
-- apricots_eaten = 0
Maybe it is a stupid concept, but I will just throw it in here...