[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua on Reddit again
- From: Dirk Laurie <dpl@...>
- Date: Sat, 5 Feb 2011 08:58:23 +0200
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
end
Choose the tool for the job. Full vectors, numeric; sparse vectors,
non-numeric.
Dirk