lua-users home
lua-l archive

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


-- untabified version (what's up with aquamacs?)

local function infix(...)
   local function eval(t)
      local l = t[1]
      if type(l) == "table" then l = eval(l) end
      for k = 2,#t,2 do
         local f, r = t[k], t[k+1]
        u if type(r) == "table" then r = eval(r) end
         l = f(l, r)
      end
      return l
   end
   return eval(...)
end

local function add(a,b)
   return a + b
end

local function sub(a,b)
   return a - b
end

local function mul(a,b)
   return a * b
end

local function div(a,b)
   return a / b
end

-- Here be { brackets, not (
print( infix{ 12 ,add, 3 ,add, 10 ,sub, { 30 ,mul, 10 } } )