Friday, October 23, 2009

List Library for Lua

I've updated my List Library for Lua which is inspired by Haskell's Data.List library.

I've had some interesting discussions about possibly specifying the arity of the list functions like for map() and filter(). Other implementations of these list functions take only one list, and any extra arguments are passed to the function called by map().

This lead to me trying an implementation where the 2nd argument to map() was the arity of the function passed in, call it N. The next N arguments are lists to be iterated over, and any arguments beyond that are passed as-is to the function. A quick example can easily illustrate:

function div(x, y) return x / y end

map(div, 2, {99, 21, 6}, {11, 7, 3}) -> {9, 3, 2}

map(div, 1, {99, 21, 6}, 3) -> {33, 7, 2}

Finally though I decided (at least for my own library) that explicitly specifying the arity was too cumbersome. If you need to a more sophisticated used is needed, some kind of wrapper for currying will be needed. Here's the 2nd use of map() above:

map(function(x) return div(x, 3) end, {99, 21, 6}) -> {33, 7, 2}

Obviously this is a little clunky. If you're using MetaLua lambda construct (or the power patch), this is considerably shortened:

map(|x| div(x, 3), {99, 21, 6}) -> {33, 7, 2}

I would really like the lambda construct accepted into mainline Lua.

Saturday, October 10, 2009

Fortunately, I had another copy on my phone...

This is just an amusing anecdote.

I was trying to download and install Reuben Thomas' stdlib. However, I'd been having problems actually downloading the file from LuaForge.

However, since I had set up the same Lua development environment on my Android phone, and I had previously installed stdlib release 12 on that, I was able to just scp over the tar archive to my laptop.

I'm still trying to remember how we all got by the the dark ages before we had the Internet. And phones that have gigabytes of storage. Seriously, what did I do before wireless LAN was widely available?