Can I use variables with assert / 1?

Now I have verified that X (Y) is not an accepted fact in my small DB. Since X (Y) returns false, it will try to approve it. (I understand that this presents problems when X is the rule, not the fact)

ifNotAdd(X,Y):- not(call(X,Y)), !, assert(X(Y)). 

For example, let's say that this fact is in DB

 mammal(dolphin). 

I ask ifNotAdd (mammal, elephant).

I want him to see it? to mammals (elephant). falsely, and then assert a mammal (elephant).

Obviously, "assert (X (Y))". the line is wrong, but what can I replace? I etch prolog documentation and forums for an answer, but so far no luck. I am also trying to write something that will do it on my own.

EDIT I โ€‹โ€‹need to edit the database to have a dynamic database with which the user can interact. I am creating an argument machine, and I need to allow the user to tell the system that they "know this fact for sure" so that the system can cope with knowledge outside its domain.

In the spirit of http://en.wikipedia.org/wiki/Reason_maintenance

Greetings

+7
source share
1 answer

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!

+8
source

All Articles