lua-users home
lua-l archive

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


>From: David Jeske <jeske@home.chat.net>
>
>I propose the following idea for making a block of code which runs
>inside the local-scope of the caller, but is otherwise similar to a
>function and evaluates as such:
>
>macro for(from,to,code)
>   local i = from
>
>   while (i<to) do
>      code(i);
>      i = i + 1;
>   end
>end
>
>
>for(1,2, macro (x)
>  print("iteration: ".. tostring(x));
>end);

I'm probably missing something here, but how is this different from a function?
What you can write right now (and it works!) is just

 function for(from,to,code)
    local i = from

    while (i<to) do
       code(i);
       i = i + 1;
    end
 end


 for(1,2, function (x)
   print("iteration: ".. tostring(x));
 end)

How would macros be different?
--lhf