lua-users home
lua-l archive

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

> Suppose we want to minimise a binary function f
> p1 = Optimize(function(x) return f(x, p2) end, p1, min, max)
> p1 = Optimize(function(x) p1 = x return f() end, p1, min, max)

Yeah!!  A meaningful suggestion.  Thanks!
I had originally considered this, but tossed the idea because its a lot of
coding and runtime effort to hand code a translation function and call it on
every iteration.

However, this usage of closures is more generic than my previously mentioned
"passing by name" method since it can actually cope with "private data
members" that might not otherwise be reachable by Optimize (or similar

It would be very nice if this construct could be reduced to a macro or a
reusable construction function, but I don't see how it can in Lua as calling
a function to create the workaround function would suffer from the original
pass by reference problem.


Thank you all for your reading time and thoughts on what is a trivial detail
(just one that has been annoyingly repetitive for my coworker).