Logic programming in C
I am trying to implement some AI planning algorithms in C, but got stuck with the basic concept :)
Before jumping to the main problem, I tried implementing some small framework that would support propositional logic:FORMULA f = PROPOSITION(a + 3 > 0);
FORMULA g = PROPOSITION(is_smaller_than(b, c));
f =开发者_JS百科 AND(NOT(f), g);
Now, the problem is that I would like not to evaluate the expressions like 'a + 3 > 0' at the moment of defining the formula, but in some later phase:
bool res = EVALUATE(f);
I guess closures would have been handy in this case, but unfortunately I also like to stick to C99.
Any idea ?
How about extending this to predicate logic ?The final goal (ideally) would be to build an AI planning library, which can be directly plugged-in to the application, and not to receive the problem as STRIPS program strings.
Thanks
OK,
As commented above I have solved the issue by using a structure with method pointer and data in it. This is the most common way of simulating closures in C.
My implementation is available here: https://github.com/pmilosev/clumsy
精彩评论