lua-users home
lua-l archive

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


Adrian Perez wrote:

...
On the other hand, { and } are harder to type. Anyway, I think your count is selective:

int i; for (i = 1; i <= 10; ++i) { ... }
for i = 1, 10 do ... end

Advantage: Lua, 16 fewer keystrokes [...]


I didn't think about that, so now it's official... Lua also beats C! (when comparing typing amount, BTW)

I hate weighing in on things like this, but there are many more cases where Lua not only requires more keystroked, but is more arcane as well.

At risk of being beaten up endlessly, how is this done in Lua?

    struct list { struct list* next } list;
    list* l;
    ... fill the list ...
    for (list* p = l; p != 0; p = p->next) { ... }

How is that done in Lua? This is both trying to illustrate that C's for loop has nice flexibility, and trying to understand how you would do something like this in Lua! I would do it like this:

    local l = { }
    ... fill the list
    local p = l
    while p ~= nil do
        ...
        p = p.next
    end

Any nicer ways?

--
chris marrin                ,""$,
chris@marrin.com          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'