You can use univ operator =../2
to construct the term before you approve it (note that the predicate in question must be declared dynamic in order for it to work)
ifNotAdd(X,Y):- not(call(X,Y)), !, Term =.. [X, Y], assert(Term).
BTW, if you want ifNotAdd/2
not fail when it does not need to add this fact to db, you should wrap this in an if structure, plus, not/1
deprecated, (\+)/1
is preferred:
:- dynamic(mammal/1). mammal(dolphin). ifNotAdd(X, Y):- ( \+ call(X, Y) -> Term =.. [X, Y], assert(Term) ; true).
But I'm not sure what you are trying to do right there. Quite often, when a newcomer to the prologue wants to manipulate the database, because the specific prolog mechanism is misunderstood. Again, you cannot be a novice, and my comment may be dumb, in which case just forget about it! But if you start, you can clarify what you are trying to achieve here, so that we can confirm that these manipulations are necessary!
m09
source share