ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.
https://dtai.cs.kuleuven.be/problog/
307 stars 36 forks source link

#dinamic predicate #77

Closed pudumagico closed 2 years ago

pudumagico commented 2 years ago

Does an option as #dynamic pred/x. exist in problog as in prolog?

VincentDerk commented 2 years ago

You're probably looking for use_module(library(assert)). which unlocks assertz/1, retract/1, retractall/1 (cf. here). It doesn't require a dynamic call.

?- use_module(library(assert)).
?- listing.

?- query(p(X)).
No clauses found for 'p/1'.
?- assertz(p(a)).
p: 1.0;
---------------
?- listing.
p(a)
?- query(p(X)).
p(a):   1

source_code of the assert library: here

pudumagico commented 2 years ago

Thank you Vincent! Although I am not quite sure this is what I am looking for. I have a program that may or not contain facts that trigger some rule, for example: `color(a).

ans(X) :- color(X). ans(X) :- size(X).

query(ans(X)).`

I want the program to stop bothering me about not having a fact for size(X).

VincentDerk commented 2 years ago

I see.

Well this is probably not the most elegant solution but my quick response would be to just add a dummy rule x :- false. and call it a day.

color(a).
size(a) :- false.  % This here will not affect the program results at all
ans(X) :- color(X).
ans(X) :- size(X).
query(ans(X)).
pudumagico commented 2 years ago

Alright, thanks a lot!