I've started a Google code project for a Lua implementation of the algorithms from the Stuart Russell and Peter Norvig book Artificial Intelligence: A Modern Approach.
I'm planning on working through the book, chapter by chapter, and creating Lua implementations of everything. In general, I'll try to stick to the spirit of the algorithms presented in the book, though there may be ways to implement them it in a more elegant and concise fashion using Lua's unique strengths.
Emphasis too will be on code that is "production ready", meaning that it can be readily incorporated into other projects.
The style of the code will vary. If it makes sense to use OO style, great. If functional seems a better fit, then I'll use that instead. I'm not as dogmatic about that kind of thing as I used to be.
I'm using a Mercurial repo, so if you'd like to contribute, just clone it and get going!
Thursday, February 11, 2010
Wednesday, November 25, 2009
SWIG and Lua
So I've been trying out SWIG with Lua recently. This was to wrap a 3rd party C library that I didn't have source for.
The initial wrapping went pretty smoothly. The only problem was that the library had its own typedef of 'bool' as an unsigned char, but SWIG treated that as a syntax error. I had hoped to avoid making copies of the header files, but ended up doing that and so commented out the typedef.
I was also a bit disappointed with the handling of some pointer types. Suppose you've got a function that takes a pointer to a double. I had expected that I could just call the wrapped Lua function with a Lua number and have that handled automatically. But I ended up declaring some pointer types, creating those C-based objects, and using those. There is some means with SWIG to declare pointer args, but I need to read that section of the docs again.
Similarly, I wanted to just pass in a table of strings and have that automatically converted to 'char **', but that is not automatic either. So that code on the Lua side is klunky too. I'm not sure that can be fixed.
I'll have to investigate luabind and toLua more.
The initial wrapping went pretty smoothly. The only problem was that the library had its own typedef of 'bool' as an unsigned char, but SWIG treated that as a syntax error. I had hoped to avoid making copies of the header files, but ended up doing that and so commented out the typedef.
I was also a bit disappointed with the handling of some pointer types. Suppose you've got a function that takes a pointer to a double. I had expected that I could just call the wrapped Lua function with a Lua number and have that handled automatically. But I ended up declaring some pointer types, creating those C-based objects, and using those. There is some means with SWIG to declare pointer args, but I need to read that section of the docs again.
Similarly, I wanted to just pass in a table of strings and have that automatically converted to 'char **', but that is not automatic either. So that code on the Lua side is klunky too. I'm not sure that can be fixed.
I'll have to investigate luabind and toLua more.
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:
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:
Obviously this is a little clunky. If you're using MetaLua lambda construct (or the power patch), this is considerably shortened:
I would really like the lambda construct accepted into mainline Lua.
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?
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?
Subscribe to:
Posts (Atom)