Such a question: Here I use a recursive search with a return, and I would like to remember the result of each found solution (for example, add to the list), which would then analyze these results. How can I arrange this?

It's just that the problem is that when we find one of the solutions and write the result (to the same list), we, since this is a return search, return to the part where it is possible to re-prove the rule, and the list to which we they brought the result of the decision, no matter how it was ... The phrase “We need a global variable” immediately comes to mind, and then programmers with an algorithmic mindset go into sadness, because there are no global variables in Prolog ... But how then to be?

By the way, I use PDC prolog.

  • You can type a list in the search process, like here . - insolor
  • the list is typed, I'm talking about some kind of final analysis of this list (1), and putting the result of this analysis into which new list (2). That old list (1) as a result of the search with a return is recruited and the list (3) is obtained, and you need to analyze it again and put the result in the list (2). - Djonny
  • What is the actual problem then? In general, without seeing the problematic piece of code, it is difficult to advise something specific. - insolor
  • The problem is that the list (2) always existed, and was supplemented as a result of evidence and proof of evidence - Djonny
  • @Djonny, still can not see the code. - insolor

1 answer 1

What is the actual question. The prologue supports the DB creation mechanism. A global variable can be replaced by a single-card relation (facts number

single pi (integer)


pi (0).

test (....): -....!, asserta (pi (.....)), ..... fail.

test ().

  • I don't understand you at all - Djonny
  • Have not tried the standard Findall predicate. Which is always possible to collect a list of facts. Facts can be added during the search with a return. Here is a ready list. - evgen