String Manipulation using SWI-Prolog -
i trying create prolog program accept input "i love you" string , output
"i love you" "i love yo" "i love y" "i love " "i love" "i lov" "i lo" "i l" "i " "i"
i using swi-prolog, , code have 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 following execute code :
?- forall(contains('i love you',x),writef("%s\n",[x])).
the following output generated shown.
i l lo lov love love love y love yo love l lo lov love love love y love yo love l lo lov love love love y love yo love o ov ove ove ove y ove yo ove v ve ve ve y ve yo ve e e e y e yo e y yo y yo o ou u
i appreciate , help. lot in advance.
i dont understand request (what mean that accept input "i love you" string
?) don't need program produce output:
?- forall(append(_, [f|s], "i love you"), format('"~s"~n', [[f|s]])). "i love you" " love you" "love you" "ove you" "ve you" "e you" " you" "you" "ou" "u" true.
the second argument of append/3 has been 'patterned' @ least of length 1, avoid last empty string result otherwise.
edit answer far it's wrong: didn't noticed shows tail! here debugged procedure, not acting generator:
pheader([x]) :- format('~s~n', [[x]]), !. pheader(l) :- format('~s~n', [l]), l = [_|xs], pheader(xs).
yields
?- pheader("i love you"). "i love you" " love you" "love you" "ove you" "ve you" "e you" " you" "you" "ou" "u" true.
then need 'program' it, @ last!
edit regain initial behaviour (header generator), here 2 argument procedure
pheader([x|xs], [x|xs]). pheader([_|xs], r) :- pheader(xs, r).
yields, @ last, desidered output:
?- forall(pheader("i love you",x),format('"~s"~n', [x])). "i love you" " love you" "love you" "ove you" "ve you" "e you" " you" "you" "ou" "u" true.
Comments
Post a Comment