Dynamic assert not taken into account

I’m using: SWI-Prolog version threaded, 64 bits, version 9.3.13-13-g530b2d433

I want the code to:
Take into account the assertions on diagnosis/2 and condition/2 made after compilation when running my predicate minimal_dataset/2.

expected result:

%test query
?- minimal_dataset([[1, 1, 0, 0, 1, 0], [1, 1, 0, 0, 0, 1]],[D,C]).
D=[0.5, 0.5, 0.7, 0.7, 0.5, 0.7]
C=[t, t, f, f, f, t]

But what I’m getting is:
The assertions are there to simulate interactive user input. What would happen is that diagnosis(1,_) would represent a positive diagnosis criterion, diagnosis(0,_) a negative criterion, and the same for condition/2. When compiling my source, the only thing known is that diagnosis/2 and condition/2 will acquire meaning only after user input. Currently, my assertions do not hold when running the test query. So, I guess I have to tell prolog to recompile minimal_dataset/2 somehow ?

My code looks like this:

%source
:-dynamic diagnosis/2.
:-dynamic condition/2.

minimal_dataset([D,C],[Diagnosis,Condition]):-
    maplist(diagnosis,D,Diagnosis),
    maplist(condition,C,Condition).

%assertion queries (run after compiling source)
?- asserta(diagnosis(1,0.5)).
?- assertz(diagnosis(0,0.7)).
?- asserta(condition(1,t)).
?- assertz(condition(0,f)).

%test query
?- minimal_dataset([[1, 1, 0, 0, 1, 0], [1, 1, 0, 0, 0, 1]],[D,C]).
false.

Thanks !

“Works for me” :smiley: You probably did something that you are not showing. Here is a log that should be reproducible on a command line:

$ cat raoul.pl 
:-dynamic diagnosis/2.
:-dynamic condition/2.

minimal_dataset([D,C],[Diagnosis,Condition]):-
    maplist(diagnosis,D,Diagnosis),
    maplist(condition,C,Condition).
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.13-19-g0ddee9acf)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [raoul].
true.

?- asserta(diagnosis(1,0.5)).
true.

?- assertz(diagnosis(0,0.7)).
true.

?- asserta(condition(1,t)).
true.

?- assertz(condition(0,f)).
true.

?- minimal_dataset([[1, 1, 0, 0, 1, 0], [1, 1, 0, 0, 0, 1]],[D,C]).
D = [0.5, 0.5, 0.7, 0.7, 0.5, 0.7],
C = [t, t, f, f, f, t].
2 Likes