|Did you know ...||Search Documentation:|
b_assertz(Term) :- assertz(Term, Ref), undo(erase(Ref)).
b_assertz(Term) :- assertz(Term, Ref), ( true ; erase(Ref), fail ).
The undo/1 based solution avoids leaving a choice point open and, more importantly, keeps undoing the assert also if the choice point from the second alternative is pruned.
Currently the following remarks apply