I'm trying to precompute some stuff and save the results as facts at the beginning of my program: (simplified code)
:- dynamic cost/2.
%recipe(Id,Cost)
recipe(1,20).
recipe(2,40).
assert_all :- recipe(Id,Cost), assert(cost(Id,Cost)).
But only the first result, cost(1,20) gets asserted when I consult the file in SICStus Prolog:
| ?- assert_all.
yes
| ?- cost(Id,Cost).
Id = 1,
Cost = 20 ? ;
no
| ?
However, when I input the right-hand side of assert_all in the SICStus prolog console directly, both cost/2 facts are there.
| ?- recipe(Id,Cost), assert(cost(Id,Cost)).
Id = 1,
Cost = 20 ? ;
Id = 2,
Cost = 40 ? ;
no
| ?- cost(Id,Cost).
Id = 1,
Cost = 20 ? ;
Id = 2,
Cost = 40 ? ;
no
I find this behavior very confusing, what's going on?