lua-users home
lua-l archive

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

Really out of my field ;) but..   just a though:

	if not X:fulfills{ in_database, need_data } then
	   get_and_put_in_database (X)

This way, you wouldn't need to duplicate the 'X' for each test function. If their prototypes are the same, the 'fulfills' function can call them one by one.


Edelleenlähetetyn viestin alku:

Lähettäjä: Johann Hibschman <>
Päiväys: maanantai, 08. maaliskuuta 2004  04:10:43 +0200
Vastaanottaja: lua list <>
Aihe: declarative syntax
Vastaus: Lua list <>

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?