lua-users home
lua-l archive

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


On Wed, May 26, 2010 at 11:39 AM, George Petsagourakis
<petsagouris@gmail.com> wrote:
> 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...
>
>

It's "nifty", but I'm not sure I'd want to use it personally. It's too
"magical" for my tastes, and it seems like this would be an addition
to the language rather than a replacement. (Would we have three for's?
numeric, tabular, and generic?)

~Jonathan