The use of this built-in is strongly discouraged, due to its non-logical behaviour! It is provided only to enable the implementation of certain low-level operations that could otherwise not be provided with the same efficiency. Surprising side effects can occur when you don't know exactly what you are doing. In particular, it must be assured by the programmer that the old argument value is not needed any longer and that the old argument was not aliased to some other location. The old value should also not be a variable.
If N is a list of integers and Term is a nested structure, then Arg is the subterm of Term described by this list of integers. E.g. setarg([2,1,3], Term, Arg) is the same as arg(2, Term, T1), arg(1, T1, T2), setarg(3, T2, Arg).
Success: [eclipse]: T = s(a, b, c), setarg(2, T, hello). T = s(a, hello, c) yes. [eclipse]: T = s(a, b, c), ( setarg(2, T, hello) ; true ). T = s(a, hello, c) More? (;) T = s(a, b, c) yes. Unpredictable result: [eclipse 10]: S=s(A), T=t(A), setarg(1, T, b). S = s(A) or S = s(b) A = b or A = A T = t(b)