Lucianpedia Wiki

Example[]

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[]

  • Grammars may be recursive (see test 9 in lpiverify4.pl), i.e. they may repeat until triggering the base case:
test(9,[[n,grammar1],["aaa"]],
[
	[[n,grammar1],[[v,s]],":-",[[[n,noun],[[v,s],""]]]],
	[[n,noun],"->",[""]],
	[[n,noun],"->",["a",[[n,noun]]]]
	],
[[]]).

Functional List Prolog (FLP)[]

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[]

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]]]], % type statements
[[[n,function],[output,output,output]]], % mode statements
[
        [[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]]]]).
test_types_cases(7,[[n,map],[[[n,add],[[[n,add],[[[n,add],[1]]]]]],0,[v,d]]],
[
[[n,map],[[t,map1],[t,number],[t,number]]], % type statements
[[t,map1],[[t,number]]],
[[t,map1],[[[t,predicatename],[[t,map1]]]]],
[[n,add],[[t,number],[t,number],[t,number]]],
[[n,getitemn],[[t,number],{[t,any]},[t,any]]]
],
[
        [[n,map],[input,input,output]], % mode statements
                
        [[n,add],[input,input,output]],
        
        [[n,getitemn],[input,input,output]]
],
[
        [[n,map],[[v,f1],[v,n1],[v,n]],":-",
        [        
                [[n,number],[[v,f1]]],
                [[n,add],[[v,n1],[v,f1],[v,n]]]
        ]
        ],
        [[n,map],[[v,f1],[v,l],[v,n]],":-",
        [        
                [[n,equals1],[[v,f1],[[v,f11],[v,f12]]]],
                [[n,=],[[v,f11],[n,add]]],
                [[n,getitemn],[1,[v,f12],[v,bb]]],
                [[v,f11],[[v,l],1,[v,l2]]],
                [[n,map],[[v,bb],[v,l2],[v,n]]]
        ]
        ],

        [[n,add],[[v,a],[v,b],[v,c]],":-",
        [       [[n,+],[[v,a],[v,b],[v,c]]]
        ]],

        [[n,getitemn],[1,[v,b],[v,c]],":-",
        [       [[n,head],[[v,b],[v,c]]]
        ]],
        [[n,getitemn],[[v,a],[v,b],[v,c]],":-",
        [       [[n,not],[[[n,=],[[v,a],1]]]],
                [[n,tail],[[v,b],[v,t]]],
                [[n,-],[[v,a],1,[v,d]]],
                [[n,getitemn],[[v,d],[v,t],[v,c]]]
        ]]

]

In the types statements above, {} denotes a list.

Equals4[]

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]]]).

LPI can enter an equals4 mode, in which arguments may be processed as lists (including atoms and predicate names), and may enter a non-equals4 mode, which doesn't replace all variable names, only [a,b] not [[c,d],[e,f]].

Findall[]

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,a1],[v,a]]],
                [v,b]]]
        ]]
        
],[[[[v,b],[1,2,3]]]]).

Maplist[]

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[]

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.

Notable Verification Tests[]

  • Test 15 - String (like atom) to list (like term) grammar parser
  • Test 17 - Split strings after ".", "!" and "?" + space, with a grammar interpreter.
  • Test 116 - Split after given characters, producing "" if one of these characters is at the start, e.g. ".aaa.bbb.", [".", "?"] produce ["", "aaa", "bbb"]
  • Test 117 - Split on given characters, returning them as well, e.g. "a   a. a ", [" ", "."] produce ["a", " ", " ", " ", "a", ".", " ", "a", " "]

Planned Features[]

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

Further Reading[]

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