I need help with understanding how to work with lists like that [a(b,c),a(x,d)] change(S,K,R) changes first list [a,c,b] with values given in second list [c(a,x),c(b,y)]
Looks like you should use Association lists.
see SWI-Prolog manual
and the online doc