How do you do a search and replace of a list with another sublist in Prolog?
I'm trying to modify a list by search and replace, was wondering how do I search through a list with the search term as a list as well? Lets say I have a list [1,2,3,4] I want to single out the 2 and 3 and replace it with 5,6 so ideally I could have a predicate: search_and_replace(Search_Term, Replace_Term, Target_List, Result_List). eg. search_and_replace([2,3], [5,6], [1,2,3,4], Result_List), write(Result_List). You can use append/2 as follows : replace(ToReplace, ToInsert, List, Result) :- once(append([Left, ToReplace, Right], List)), append([Left, ToInsert, Right], Result). With or without