Reputation: 1388
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.
Upvotes: 9
Views: 3286
Reputation: 781
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
Upvotes: 0
Reputation: 31810
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)
)).
Upvotes: 1
Reputation: 22421
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.
Upvotes: 0