| ?- [rules].
compiling /home/wujek/Playground/
rules.pl for byte code...
/home/wujek/Playground/
rules.pl compiled, 2 lines read - 755 bytes written, 13 ms
yes
| ?- product([6], [3, 2]).
yes
| ?- product([4, -6, 25], [1, 4, -3, 2, 5, 5]).
yes
| ?- product([4, -6, 25], [1, 4, -3, 2, 5, 4]).
no
| ?- product([4, -6, 25], [1, 4, -3, 2, 5]).
no
The questions are:
1. my first attempt in the first goal was:
L1Head = L2First * L2Second, which apparently isn't true. Why doesn't it work? Why do I need the 'is' word there? It looks like prolog doesn't compute the value before unification, but why?
2. When I rewrite the program so:
product([], []).
product(L1, L2) :- [L1Head|L1Tail] = L1, [L2First|[L2Second|L2Tail]] = L2, L1Head is L2First * L2Second, product(L1Tail, L2Tail).
prolog asks me each time if it is true, instead of just saying 'yes' as before (it does say 'no' right away, tho):
| ?- product([], []).
true ? % I have to press [enter] here
yes
Why does this happen?
Regards,
wujek