Lua Fun: A high-performance functional programming library designed for LuaJIT
github.com
github.com
Please considering sponsoring [1] LuaJIT so that Mike can continue working on it.
Lua Fun looks like a wonderful addition to the Lua ecosystem.
Because most HNers are web developers and care only about the browser.
Lua is really strong in the game developer community.
pjmpl just meant we don't see a lot of game developer content on here, which is largely a C++ dominated area (with Lua game scripting becoming a lot more common).
All of them languages which are mostly used for web.
Edit: [3] has a good exlanation of how stream fusion works, and it should make it clearer why the linked code appears to be doing the same thing.
see also here[2] for a further paper on stream fusion being used to produce vectorised code. I've linked to the reddit comments because there's some useful discussion there too.
[1] http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.104.7...
[2] http://www.reddit.com/r/haskell/comments/1br0ls/haskell_beat...
[3] http://donsbot.wordpress.com/2008/06/04/haskell-as-fast-as-c...
Take this example containing functional composition and higher-order functions:
reduce(operator.add, 0, map(function(x) return x^2 end, range(n)))
LUA converts this into 10 lines of assembler (2 jumps). Also, the LUA compiler is directly generating SSE.
Anyone have any good benchmarks comparing simple functional examples in LUA with Clojure or Common Lisp?
Is -- calculate sum(x for x^2 in 1..n) a comment or is it the output of a code transform?
The point is not about expressiveness; it's that while this code composes several higher-order functions, it's compiled into the kind of assembly code you'd expect from a fully optimized C routine.
Two more up-to-date forks can be found here....
- https://github.com/jtarchie/underscore-lua
- https://github.com/mark-otaris/underscore.lua
NB. The jtarchie fork seems best because its got 59 stars & 5 contributors.
[1] http://docs.python.org/2/library/itertools.html [2] http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Li... [3] http://www.standardml.org/Basis/list.html
Any particular reason for that?
Lua 5.1 can run fun.lua after minor changes (I'll make patch soon), but I am not sure that performance will be good enough.
Also, are you using lots of 5.1 specific stuff (setfenv, ...) or would this also be easily ported to 5.2?
Some high-order functions heavily use recursion just to support multireturn iterators (yes, you can use multireturn with map, reduce, filter and so on). I plan to benchmark these parts and add optimized versions for non-JIT Lua if necessary.
I will try to make a patch in the next couple of days. Thanks for your interest!