lua-users home
lua-l archive

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


On Jan 3, 2010, at 4:57 AM, Mike Pall wrote:

> The sequence version runs in the interpreter, because calls to
> vararg functions are not compiled, yet. The open coded version
> runs 33x faster than with Lua.
> 
> But do you really seriously think that this:
> 
>  for v in s.seq( plus_one, 0, 0 )( s.take, limit )( s.filter, is_odd )( s.map, square )( s.iterator ) do
>    total = total + v
>  end
> 
> is more readable than this:
> 
>  for i=1,limit do total = total + i*i*(i%2) end
> 
> I mean ... apart from the fact that the latter is 80x faster than
> the former under LuaJIT. :-)

No, I don't think it's clearer. The multiply by i % 2 is subtle, but I'd thought about something similar as a way to optimize the test code if my goal had been to avoid conditionals.

I do, however, think examples like:

	iseq(io.lines(arg[1])) (take,10) (foreach, print)

Are probably clearer than:

	local count = 0

	for line in io.lines(arg[1]) do
		count = count + 1
		if 10 < count then break end
		print( line )
	end

Mark