lua-users home
lua-l archive

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


2013/11/18 Stéphane Aulery <lkppo@free.fr>:

> I do not know if this is doable, but I would find it convenient to name
> the return values of functions to facilitate code maintenance.

Simply use informative variable names.

function statistics(x)
local mean, variance, standard_deviation = 0,0,0
for k=1,#x do mean = mean+x[k] end
mean = mean/#x
for k=1,#x do variance = variance+(x[k]-mean)^2 end
variance = variance/#x
standard_deviation = sqrt(variance)
return mean, variance, standard_deviation
end