Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic programming in Lua?

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.

like image 581
mnicky Avatar asked Feb 18 '12 08:02

mnicky


People also ask

How many logical operators are there in Lua?

In Lua language, there are basically 3 logical operators which are 'and', 'or' and 'not'. These logical operators are quite useful to solve complex decision-making problems. In Lua, 'and' logical operator considers 'nil' and 'false' as false else all the other operands are considered to be true.

What is == in Lua?

The operator == tests for equality; the operator ~= is the negation of equality. We can apply both operators to any two values. If the values have different types, Lua considers them different values. Otherwise, Lua compares them according to their types. Specifically, nil is equal only to itself.

What coding programs use Lua?

Lua can be used in everyday applications to extend the existing functionality or create new features and functions. Some popular games, programs, and services that use Lua are Dark Souls, Fable II, Garry's Mod, Wireshark, VLC, Apache, and Nginx Web Servers.

Is Lua a coding language?

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.


1 Answers

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)
    )).
like image 73
Anderson Green Avatar answered Sep 18 '22 15:09

Anderson Green