lua-users home
lua-l archive

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

On Sat, Feb 05, 2011 at 01:33:17AM +0200, Andrew Lentvorski wrote:
> 3) The fact that I have to write a numeric "for" to iterate in this day 
> and age ticks me off. :)

Python goes out of its way to make the numeric "for" unattractive.

Non-numeric:    z = [a*xi+yi for xi,yi in zip(x,y)]
Numeric:        n = min(len(x),len(y))
                z = n*[0]
                for i in range(n) do z[i] = a*x[i]+b[i]

Sure, that ticks me off too.  

But in Lua:

Numeric:        z={}
                for i=1,min(#x,#y) do z[i] = a*x[i]+b[i] end
Non-numeric:    z={}
                for k,xk in pairs(x) do
                    local yk=y[k]
                    if yk then z[k]=a*xk+yk end

Choose the tool for the job.  Full vectors, numeric; sparse vectors,