lua-users home
lua-l archive

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



On 30-Aug-05, at 12:20 PM, Boyko Bantchev wrote:

On 8/30/05, Rici Lake <lua@ricilake.net> wrote:
Try:

DO(i, 0, 9,
    int j, k;
    j = 2 * i;
    k = i + 1;
    printf("i = %d, j = %d, k = %d\n", i, j, k);
);

Sure, can't use commas here.  Everything has its limitations,
and perfection is but a mirage :)
In this case, I'd have to write   int j; int k;  instead.

Leading to the likelihood of obscure compiler warnings with this construct.

Even so, let's contrast:

imac:~ rici$ cat c.test
#include "do.h"
DO(i, 0, 9,
  int j = 2 * i;
  int k = i + 1;
  printf("i = %d, j = %d, k = %d\n", i, j, k);
);
imac:~ rici$ cat lua.test
for i = 0, 9 do
  local j, k = 2 * i, i + 1
  print(string.format("i = %d, j = %d, k = %d", i, j, k))
end
imac:~ rici$ wc c.test lua.test
       6      30     112 c.test
       4      29     106 lua.test

OK, without the include it would have favoured C by 10 characters, but then I could have used a Lua header with:

  function printf(...)
    print(string.format(...))
  end

thereby saving about 13 characters in Lua.

Conclusion: concision is not the issue. The issue is personal taste. The "conciseness" of C is mostly illusory. :)