So I have this quick question. I created a predicate called "slide" that (slides) through a List performing some basic pattern matching (I know someone will say there is already a predicate for that, but its also a learning exercise--although I would like to know the predicate name!). Here is one of the declarations:
Code: Select all
slide : (Elem* Source, Elem V1, Elem V2, Elem V3) nondeterm anyflow.
Hopefully it is clear I want V1, V2, V3 to be either "in" or "out" parameters so I can make calls like this (not a very good example but hopefully you get the idea):
Code: Select all
L = [ V || slide(["I", "am", "who", "I", "said", "I", "am"], V, "I", _V2) ]
-or-
L = [ Keyword1 || slide(["I", "am", "who", "I", "said", "I", "am"], "I", Keyword1, _Keyword2) ]
Code: Select all
predicates
% o o o
% o o i
% o i i
% i o o
% i i o
% i i i
% o i o
% i o i
slide4 : (Elem* Source, Elem V1 [out], Elem V2 [out], Elem V3 [out]) nondeterm.
slide4 : (Elem* Source, Elem V1 [out], Elem V2 [out], Elem V3) nondeterm.
slide4 : (Elem* Source, Elem V1 [out], Elem V2, Elem V3) nondeterm.
slide4 : (Elem* Source, Elem V1, Elem V2 [out], Elem V3 [out]) nondeterm.
slide4 : (Elem* Source, Elem V1, Elem V2, Elem V3 [out]) nondeterm.
slide4 : (Elem* Source, Elem V1, Elem V2, Elem V3) nondeterm.
slide4 : (Elem* Source, Elem V1 [out], Elem V2, Elem V3 [out]) nondeterm.
slide4 : (Elem* Source, Elem V1, Elem V2 [out], Elem V3) nondeterm.
Thanks in advance!
P.S. For context, here the source for a simpler version (slide3) if it will help.
Code: Select all
% TEST FOR END OF LIST
slide([_H], _V1, _V2) :-
fail.
% TEST FOR THE SUCCESS CASE
slide([H, TH | _TT], V1, V2) :-
V1 = H,
V2 = TH,
succeed.
% RECURSE
slide([_H | T], V1, V2) :-
slide(T, V1, V2).