(compiler: SWI Prolog
)
In the numerical list, replace all occurrences of positive values with negative elements of the same list, passing the list in order. Example.
?-replace_positive([1,-2, 3, -4, -5, 6, 7, 8], X) X = [-2, -2, -4, -4, -5, -5, 'No', 'No']
I tried something like that, backtracking one step back, but something doesn't work
replace_positive([H|T],LN,[H1|R]):- (H < 0), H1 = H, LN1 = H, replace_positive(T, LN1, R), H is LN1.