[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: iterating over ... ?
- From: Sam Roberts <vieuxtech@...>
- Date: Wed, 6 Apr 2011 12:09:48 -0700
On Wed, Apr 6, 2011 at 11:50 AM, Benoit Germain <bnt.germain@gmail.com> wrote:
>> The original request was to avoid calling select or creating tables,
>> hence the increased length and lack of support for nil in my
>> proposals.
I was trying to think of a way to implement this in C, where the stack
is often more visibly a stack, but I couldn't think of a good way, can
anybody else?
The best I could think of would be writing a foreach style function:
foreacharg(f, ....)
that calls f for each value in ... without having to call select()
over and over, pushing ... onto the stack.
> Oh well, all this stemmed from the fact that I initially tried to index ...
> with operator [] like I could have done for a table, and this failed because
> ...[n]
> behaves as
> {...}[1][n]
> instead of
> {...}[n]
You probably know this, but for the record, no temp tables are
constructed and discarded.
...[n]
is syntactically invalid, the valid lua code would be:
(...)[n]
where the () discards all but the first value, behaving like:
v = ...
> But as I said, this is no big deal.
But generated interesting and educational code. I liked the linked
list of closures, I might have a use for that some day.
Cheers,
Sam