Best way to define a predicate in Prolog

I have a problem defining procedures in Prolog. I have two source files and you want to consult the Prolog engine with both of them. This can be done by calling Prolog as swipl -g "['1.pl', '2.pl'].

Both files are generated by another program written in a different programming language, and I cannot predict the exact contents of the files in advance.

The problem is that one of the files always has a rule

predicate1(X):-predicate2(X).

But sometimes the rule

predicate2(something):-body

does not exist in both files, and I get the error "predicate2" undefined when I execute some queries for predicate1.

If I include the string

:- dynamic(predicate2/2). 

, /2 ( - " , 2/2?". -, .

, , "". SWI-Prolog SICStus Prolog. ( , , )

+2
3

SWI Prolog . ISO

:- set_prolog_flag(unknown, Choice).

- (, , ).

, :

swipl -g "set_prolog_flag(unknown,fail),['1.pl','2.pl']."

:

swipl -g "assert(predicate2(_):-fail),['1.pl','2.pl']."

+2

predicate2/2 multifile ISO . predicate2/2:

:- multifile(predicate2/2).

, , .


@CapelliC - . , !

, dynamic(predicate2/2), predicate2(_). , ?

+3

, Prolog , . , ,

?- isDuck(Donald) .
! ----------------------------------------
! Error 20 : Predicate Not Defined
! Goal : isDuck(_17610)

Prolog , , "-" . , , isDuck/1 (Predicate Not Defined), Prolog , "-" . , , , , , , . , Prolog - . . , , . , , Prolog , , Prolog . Prolog , , , . , , Prolog (, ), , Prolog (, ). . . , () . Prolog . , .


-1
source

Source: https://habr.com/ru/post/1584730/


All Articles