lua-users home
lua-l archive

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

On Monday 14 June 2004 16:39, Virgil Smith wrote:
> > Since Lua allows multiple return values,
> > you can always just use the idiom:
> >
> > a = f(a)
> The case at hand is a multivariate optimization problem (and several
> similar issues).
> a = f(a)
> is not a valid solution, as it does not allow the creation of a function
> that performs the optimization in a general fashion.

Playing around with globals in that manner is terrible style. Suppose we want 
to minimise a binary function f w.r.t. the first parameter:

p1 = Optimize(function(x) return f(x, p2) end, p1, min, max)

Now Optimize is always passed a function in a single variable, regardless of 
the actual implementation of the function to minimise. This is actually 
generic, as opposed to assuming that the function operates on table members. 
If you really want to use table members:

p1 = Optimize(function(x) p1 = x return f() end, p1, min, max)

> Frankly he's just tired of having to write extra code because Lua is
> missing a key feature of almost all popular programming languages (i.e. the
> ability to pass by reference).

Most popular languages have goto as well. Doesn't mean it's a good thing. 
Value semantics are widely recognised as resulting in cleaner code.
-- Jamie Webb