lua-users home
lua-l archive

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


Hi,

I read the wiki page on Short Anonymous Functions ( http://lua-users.org/wiki/ShortAnonymousFunctions ), and noticed that there's nothing there that proposes the approach that is (or at least was a few years ago) used in the Boost Lambda Library: make special argument placeholder objects (say _1, _2 ..._N), and overload the operators for these to return callable objects.

This means you can, for example:

function test(f)
  for i = 1, 10 do
    print(f(i, 20))
  end
end

test(_1 + 100 + _2)

Does anyone have any comments on or interest in such an approach? I've attached working proof-of-concept code that only handles addition, but clearly you could do much more.

My interest is in writing a binding to Linear Program solvers (CLP in the first instance) and I'm fiddling with nice ways of expressing constraints. In this case you have variable placeholders rather than argument placeholders, but it's pretty much the same.

Cheers,
Geoff


Attachment: lambda.lua
Description: Binary data