Example[edit | edit source]

List Prolog Interpreter (LPI) is a version of Prolog that can be used to write algorithms with CAWMP  because the List Prolog algorithms are in list format. See all examples.

For example:

test(7,[[n,reverse],[[1,2,3],[],[v,l]]],
[
        [[n,reverse],[[],[v,l],[v,l]]],
        [[n,reverse],[[v,l],[v,m],[v,n]],":-",
        [       [[n,head],[[v,l],[v,h]]],
                [[n,tail],[[v,l],[v,t]]],
                [[n,wrap],[[v,h],[v,h1]]],
                [[n,append],[[v,h1],[v,m],[v,o]]],
                [[n,reverse],[[v,t],[v,o],[v,n]]]
        ]
        ]
],[[[v,l], [3, 2, 1]]]).

Grammars[edit | edit source]

Definite Clause Grammars in List Prolog are like base cases, e.g. test 15:

	  [[n,compound212],["","",[v,t],[v,t]]],

and a "bottom case" in case it is not at the end of the string, e.g.:

		  [[n,compound212],[[v,u],[v,u],[v,t],[v,t]]],

given the clause:

		  [[n,compound21],[[v,t],[v,u]],"->",
		  [[[n,a]],
		  [[n,code],[[n,wrap],["a",[v,itemname1]]],
		  [[n,append],[[v,t],[v,itemname1],[v,v]]]],
		  [[n,compound212],[[v,v],[v,u]]]]],

Functional List Prolog (FLP)[edit | edit source]

Predicate names and variables may be substituted for variable names, e.g. in [[n,function],[[[n,function2],[2]],1,1,[v,c]]] function2 is passed as a variable.

Strong Type Statements[edit | edit source]

FLP may optionally use strong type statements, e.g.

test_types_cases(2,[[n,function],[[v,a],[v,b],[v,c]]],
[[[n,function],[[t,number],[t,string],[t,predicatename]]]],
[
        [[n,function],[[v,a],[v,b],[v,c]],":-",
        [
                [[n,=],[[v,a],1]],
                [[n,=],[[v,b],"a"]],
                [[n,=],[[v,c],[n,a]]]
        ]]
]
,[[[[v,a], 1],[[v,b], "a"],[[v,c], [n,a]]]]).

Equals4[edit | edit source]

LPI includes a system command call equals4, which pattern matches lists and lists of lists, etc. to other lists, e.g.

test(79,[[n,equals41],[[1,2,3],[v,b]]],

[
        [[n,equals41],[[v,a],[v,b]],":-",
        [       [[n,equals4],[[v,a],[[v,b],"|",[v,c]]]]
        ]]
        
],[[[[v,b],1]]]).

Findall[edit | edit source]

LPI's findall command finds non-deterministic results of its body and returns them in a list, e.g.

test(77,[[n,findall1],[[1,2,3],[v,b]]],

[
        [[n,findall1],[[v,a],[v,b]],":-",
        [       [[n,findall],[[v,a1],[[n,member2],[[v,a],[v,a1]]],
                [v,b]]]
        ]]
        
],[[[[v,b],[1,2,3]]]]).

Maplist[edit | edit source]

LPI's maplist command recursively runs a command on the given input, e.g.

test(78,[[n,maplist1],[[1,2,3],[v,b]]],

[
        [[n,maplist1],[[v,a],[v,b]],":-",
        [       [[n,maplist],[[n,+],[v,a],0,[v,b]]]
        ]]

        
],[[[[v,b],6]]]).

International LPI API Integration[edit | edit source]

List Prolog Interpreter may run algorithms in languages other than English, through integration with a dictionary generator for other languages, documentation generator and algorithm translator.

Planned Features[edit | edit source]

SSI (State Saving Interpreter) with the redo feature in trace.

Further Reading[edit | edit source]

See also Text to Breasoning (formerly part of the List Prolog Interpreter Repository).

Community content is available under CC-BY-SA unless otherwise noted.