Hi Uzaku,
(is)/2 is not a true relation, because it cannot be used in all directions. Therefore, you cannot reason in this way about it, as the algebraic properties you expect from logical relations (in this case: commutativity of conjunction) do not hold for these low-level primitives.
There is a declarative alternative which should be used instead to obtain more general and declarative programs, especially if you are just beginning to learn Prolog: You get the behaviour you expect if you simply use
constraints instead of low-level arithmetic predicates. Constraints can be used in all directions as true relations and are therefore much easier to understand.
For constraints over integers, add:
:- use_module(library(clpfd)).
at the beginning of your program, and replace
(is)/2 by
(#=)/2 throughout.
alsoPleaseConsiderWhatYouFindEasierToRead: mixed_caps_or_underscores_for_predicate_names?
After these changes, the second query also yields a solution:
?- sq_list(O1, O2), sum_list([2,3,4], O1).
and lets you observe its nontermination when you press SPACE.
In addition, the resulting predicates can also be used in the most general way (i.e., all arguments variables) , which was not possible before.
All the best,
Markus