Assert ssu goal with guards

Does anybody know how to assert a dynamic Single-Sided Unification (SSU) clause with a guard ?
Trying to do an assert with an SSU goal with guards results in an exception:

?- assertz(((toto, true) => true)).
ERROR: No permission to modify static procedure `(',')/2'
ERROR: Defined at /home/kwon-young/prog/swipl-devel/install/lib/swipl/boot/init.pl:400
ERROR: In:
ERROR:   [12] assertz((toto,true=>true))
ERROR:   [11] toplevel_call(user:user: ...) at /home/kwon-young/prog/swipl-devel/install/lib/s
wipl/boot/toplevel.pl:1519

Trying to expand the SSU goal with a guard results in the exact same expression:

?- expand_term(((toto, true) => true), T).
T = (toto, true=>true).

Just found out. Turns out the transformation is done in swipl-devel/boot/init.pl at 5433f58c67578560e2474cbaa2985eda1350b5b7 · SWI-Prolog/swipl-devel · GitHub

I believe we need to do that transformation ourselves, so I made this little helper predicate:

assert_ssu((Head, Guard) => Body) =>
   assertz(?=>(Head, (Guard, !, Body))).
assert_ssu(Head => Body) =>
   assertz(Head => Body).

adapt as you wish :slight_smile: