lua-users home
lua-l archive

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


I wrote a library to do Erlang-style pattern matching in Lua. Rather
than writing a series of nested ifs to test/switch on a table's
structure, you can just specify the table itself, possibly with
variable captures.

tarball: http://silentbicycle.com/lua/tamale.tgz
zip: http://silentbicycle.com/lua/tamale.zip
github: http://github.com/silentbicycle/tamale

It's implemented in pure Lua (tested with Lua 5.1.4), so it should be
quite portable, and it's reasonably efficient. It uses linear search,
with indexing on the first pattern value (as in Erlang and Prolog). I
tried compiling the pattern spec into CPS, but the compilation (which,
being Lua, happened at runtime) took too long, and only slightly
improved the matching speed.

For usage examples, see the README, API docs, benchmark, and test suite.

I hope it's useful!
Scott