The predicate join23 defined below shows how to join two str

The predicate join2/3 defined below shows how to join two strings (the first two arguments) to create a third string 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 */ ioin2 (Stringl, String2 , Newstring) : name (String1, L1) , name (String2, L2), append (L1, L2, Newlist ) name (Newstring, Newlist )

Solution

/*Join two strings String1 and String2 to form a new string NEwstring */

join2(String1, String2, Newstring) :-
   name(String1, 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 join2 and join3 predicate */
join4(String1, String2, String3, String4, Newstring) :-
   join3(String1, String2,String3 S),
   join2(S, String4, Newstring).

 The predicate join2/3 defined below shows how to join two strings (the first two arguments) to create a third string combining the two. The programming techniq

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site