首页 > 解决方案 > 如何在 java netbeans 中调用这个 Prolog 代码

问题描述

/* medical diagnostic system

start with ?- check.
*/   

check:-
    checkfor(Disease),
    write('I believe you have '),
    write(Disease),
    nl,
    undo.

/* disease to be checked */   

checkfor(cold):- cold.

/* cold */

cold:-
    checkSymptom(a),
    checkSymptom(b),
    checkSymptom(c),
    nl.

askQuestion(Question):-
    write('Do you have the Symptom '),
    write(Question),
    write('?'),
    read(Reply),
    nl,
    ( (Reply == yes ; Reply == y)
    -> assert(yes(Question))
    ; assert(no(Question)), fail
    ).

:- dynamic yes/1,no/1.

checkSymptom(S) :-
    ( yes(S)
    -> true
    ; ( no(S)
      -> fail
      ; askQuestion(S)
      )
    ).

undo :- retract(yes(_)), fail.
undo :- retract(no(_)), fail.
undo.

标签: netbeansprolog

解决方案


推荐阅读