Adjust the following program to join four strings instead of
Adjust the following program to join four strings instead of three.
The predicate join2/3 defined below shows him to join two strings (the first two arguments) to create a third siring combining the two. The programming technique used is a typical one in string processing: convert both strings to lists, concatenate them using append and finally convert back the resulting list to a string./* Join two strings String1 and String2 to form a new string Newstring */join2(Stringl, String2, Newstring):- name(String1, L1), name(String2, L2), append(L1, L2, Newlist), name(Newstring, Newlist). The predicate join3/4 defined below uses join2 twice to join three strings together./* Join three strings using the join2 predicate */join3(String1, String2, String3, Newstring): - join2(String1, String2, S), join2(S, String3, Newstring). Now, make a prolog program to join four strings. Run it. Submit the program and a fewSolution
Hi, Please find my solution:
Given:
    join2(String1, String2, Newstring):-
        name(String2, L1), name(String2, L2),
        append(L1, L2, Newlist),
        name(Newstring, Newlist).
    join3(String1, String2, String3, Newstring):-
        join2(String1, String2, S),
        join2(S,String3,Newstring).
 /* Join four strings using the join2 and join3 predicate */
   join4(String1, String2, String3, String4, Newstring):-
        join3(String1,String2, String3, S),
        join2(S, String4, Newstring).

