Introduce new facts in prolog by asserta

1

I've been trying to use both asserta and assertz in my program and the compiler does not stop telling me

  

No permission to modify static procedure 'asserta / 1'

I've been reading other messages and theoretically should be solved by saying: -dynamic the problem is that I still get error, this is the code I used in an example to try to see why it fails.

prueba(abc).
prueba(123).
:- dynamic prueba/1.
asserta(prueba('666')).

I have tried placing the dynamic in another site, but nothing, both with asserta and with assertz and I get an error and I do not know why, I have also tried removing the single quotes ''.

It only leaves me with assert the problem is that assert does not do anything, when checking then the facts that make true test does not appear the one introduced.

I was asking because the truth that I am blocking is that I do not know what to do, because any example that I see, the asserta is used in runtime not in the program itself and only the use of dynamic is mentioned without giving a complete example.

    
asked by David Pinedo Solano 02.05.2018 в 23:21
source

1 answer

1

I give an example of what I did in my program, in case someone happens to the same question, know how to solve it and have an example on which to base.

relacionDesconocidos(Persona1, Persona2):- asserta(sonDesconocidos(Persona1,Persona2)).

In this case, it is a rule that indicates that if 2 people are unknown, add to the rules, which are not known, basically it is to check if 2 people knew each other or not, once we confirmed the fact, we added that relation, The error that can occur with aserta , unlike assert , is that assert can be included alone. Example:

assert (sonDesconocidos(Persona1,Persona2)).

That would introduce the fact without necessity, to check any condition or rule.

However, with asserta and other versions of assert , it must be part of a rule, otherwise it will give an error. Then it should be like this:

condicion o regla:- asserta(hecho a introducir()).
    
answered by 14.11.2018 в 14:55