I am trying to create a prolog program that accept input "i love you" as a string and then output
"i love you"
"i love yo"
"i love y"
"i love "
"i love"
"i lov"
"i lo"
"i l"
"i "
"i"
I am currently using SWI-Prolog, and the code I have is the following.
sublist(S, L) :-
append(_, L2, L),
append(S, _, L2).
contains(A, B) :-
atom(A),
name(A, AA),
contains(AA, B).
contains(A, B) :-
sublist(B, A),
B \= [].
I use the following to execute the code :
?- forall(contains('i love you',X),writef("%s\n",[X])).
The following is the output generated exactly as shown.
i
i
i l
i lo
i lov
i love
i love
i love y
i love yo
i love you
l
lo
lov
love
love
love y
love yo
love you
l
lo
lov
love
love
love y
love yo
love you
o
ov
ove
ove
ove y
ove yo
ove you
v
ve
ve
ve y
ve yo
ve you
e
e
e y
e yo
e you
y
yo
you
y
yo
you
o
ou
u
I appreciate any and all help. Thanks a lot in advance.