Prolog - How to assert/make a database only once

后端 未结 2 1192
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 00:33
resultList(UsersQuery):-
    question(X,H),
    write(H),
    myintersection(H,UsersQuery,Match,TotalQuestionKeywords),
    Percent is Match/TotalQuestionKeywords*100,
          


        
2条回答
  •  走了就别回头了
    2021-01-21 01:20

    Make a separate predicate for assertion that checks if fact is not yet asserted:

    assertThisFact(Fact):-
        \+( Fact ),!,         % \+ is a NOT operator.
        assert(Fact).
    assertThisFact(_).
    

提交回复
热议问题