9

Is there a way to do logic programming (think of Prolog) in Lua?

In particular: is there any Lua module for logic programming (miniKanren implemenatation will be the best, but it isn't strictly required)? Because I couldn't find any [1]. And if not, are there any known (preferably tried) ways how to do logic programming in Lua?

Also: is there anybody who has tried to do something like logic programming in Lua?


[1] So far I've found only blog post mentioning the possibility of writing one in Metalua, but I would rather see one compatible with the standard Lua.

6
  • 1
    Isn't all programming logic? You might elaborate a bit for people not familiar with logic programming. I'm sure you can concoct something using metatables. Commented Feb 18, 2012 at 15:09
  • Ok, I've added some hints on Logic programming... You know, I can try something like playing with metatables, but at first I wanted to know whether anybody else has tried to do something like this before me... Commented Feb 19, 2012 at 15:01
  • Second hit on google for 'Lua "logic programming" library' gives you a pdf about multiple paradigm programming in Lua, where section 5 has some references to prolog. While not a complete library (doesn't seem there is one), it might give you some pointers. Commented Feb 19, 2012 at 18:05
  • Yes, I've seen that before, but thanks :-). That text gives a few points (though nothing substantial), but it really seems there isn't anything more written about logic programming in Lua world yet..... Commented Feb 23, 2012 at 23:56
  • 2
    You may find this article useful: fawkesrobotics.org/publications/2010/aaai2010spring-golog-lua Commented May 5, 2012 at 4:24

3 Answers 3

1

There is a forward-chaining inference engine in Lua called lua-faces. In addition to MiniKanRen, there are several other logic programming systems in JavaScript that could be automatically translated into Lua using Castl.

I also wrote a translator that converts a subset of Lua into Prolog. Given this input:

function print_each(The_list)
    for _, Item in pairs(The_list) do
        print(Item)
    end
end

it will produce this output in Prolog:

print_each(The_list) :- 
    forall(member(Item,The_list),(

        writeln(Item)
    )).
Sign up to request clarification or add additional context in comments.

Comments

0

Logic programming is a paradigm and thus is just a form of specific syntax where you state some facts and base result on logical equation of those facts, while facts themselves could be results of other equations.

Lua is not specifically designed for this, but you can easily simulate this behavior by defining all logic programming operators as functions - i.e. function and(...) that would return true only if all its arguments true, etc., and making defining your "facts" as a table with lazy evaluation provided by metatable.

Comments

0

Would ASP be helpful? https://potassco.org/

Check section 3.1.14 of the manual https://github.com/potassco/guide/releases/download/v2.1.0/guide.pdf

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.