Page 1 of 1

making predicates procedures - single facts?

Posted: 5 Apr 2021 22:52
by dcgreenwood
I keep running into the situation where I need a predicate or a stretch of code to be procedural, such as in a "for each do".

I have a few databases of facts that are used as lookups (with many members) but then I also am using quite a few facts as ways to hold pieces of changeable information. In a different language, I would do this with global variables, but my understanding is that facts are the only way to have variables that persist across predicates.

(side question - is that true? Is there another way?)

But, if I pull information from one of these facts, it makes the code either nondeterm, or if I declare the fact as determ, then the code is determ. I need it to be procedural.

It occurs to me that I could declare the fact as single, which should make any access to it procedural. But, is there any way to change a fact declared as single? Since you can't retract it, I assume it cannot be changed...it is a constant?

So my questions are:
1) Can a fact declared as single be changed (and if so, how).
2) Is there another construct to hold a single piece of information that can be changed, like I would use a global variable for in another language?
3) Is there some other way to ensure that code that is looking up information in deterministic facts is still procedural and not deterministic? Surrounding the fact references with cuts doesn't seem to work. I guess I could just not use facts and always pass the information back and forth between all the predicates that need to be able to access it

Re: making predicates procedures - single facts?

Posted: 6 Apr 2021 11:37
by Thomas Linder Puls
single facts are automatically retracted when a new fact is asserted.

But in general I think you should use fact variables:

Code: Select all

facts     someValue : integer := 2.
See also Facts, and it is also a good idea to follow the tutorials.