lua-users home
lua-l archive

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

Has anyone thought much about doing declarative-style, logic-like programming in Lua? I know the syntax is supposedly good for such things, but has anyone actually done a backward-chaining engine for Lua?

I want to put together a usable declarative syntax for database and filesystem updates, something where I can merge 'primitive' tests, like:

function last_modified (f) ... end    -- get the last-modified date
function in_database (rec) ... end    -- check the database

with rules for actions

if not in_database (X) and need_data (X) then
   get_and_put_in_database (X)

and statements of the state of the world

need_data_for_all {June, July, August, September}

and so on.

I can handle writing your basic horribly-inefficient backward-chaining engine. I'd have to look up those silly predicate logic terms, but everything is small enough that half-remembered stuff from Intro to AI should be good enough.

What I am having problems with is figuring out how to write those "if" rules in a way that is pretty and readable enough to make the project worthwhile.

Any suggestions?