Visual Prolog流模式不存在

时间:2016-05-07 01:36:41

标签: prolog visual-prolog

我正在编写一个猜测动物的专家系统。这是讲师提供的一个例子。我使用视觉序言,但我收到了编译错误,我无法理解。你能帮帮我吗?

#include @"pfc\core.ph"

implement program
    open core

class facts -database
     db_make_sure : (symbol,symbol).
     db_denied : (symbol,symbol).
      have_found : (symbol).

 predicates
    do_animal : ().
    find_animal : ().
    it_is : (symbol).
    make_sure : (symbol,symbol).
    denied : (symbol,symbol).
    remember : (symbol,symbol,symbol).
    ask : (symbol,symbol).
    test1 : (symbol).
    test2 : (symbol,symbol).
    test3 : (symbol,symbol,symbol).
    test4 : (symbol,symbol,symbol,symbol).
    do_expert_job : ().
    clear_facts : ().

 /* USER INTERFACE SYSTEM */

clauses
 do_expert_job() :-
   console::nl,console::write("---------------------------------------"),
   console::nl,console::write("|  WELCOME TO A ANIMAL EXPERT SYSTEM |"),
   console::nl,console::write("|                   |"),
   console::nl,console::write("| This is a classification program  |"),
   console::nl,console::write("|    (it guesses animals)     |"),
   console::nl,console::write("| that works by forwards chaining.  |"),
   console::nl,console::write("| Please respond by typing in    |"),
   console::nl,console::write("|   'yes' or 'no'         |"),
   console::nl,console::write("---------------------------------------"),
   console::nl,console::nl,

 do_animal,
   console::write(" Press Space Bar "),console::nl,
   _ = console::readChar(),
   console::clearOutput,
   console::close.

 do_animal():-
   find_animal,
   have_found(X),!,console::nl,
   console::write(" Your animal may be a(n) ",X,"."), console::nl,
   _ = console::readChar(),
   clear_facts.

 do_animal() :-
   console::nl,console::write(" Sorry , unable to determine the animal."), console::nl,
   _ = console::readChar(),
   clear_facts.

 ask(X,Y) :-
   console::write("Question :- ",X," it , ",Y," ?  "),
   R = console::readLine(),
   remember(X,Y,R).

 /* INFERENCE ENGINE  */
 find_animal() :-
  test1(X),
  test2(X,Y),
  test3(X,Y,Z),
  test4(X,Y,Z,_),!.
  find_animal().

  make_sure(X,Y) :-  db_make_sure(X,Y),!.
  make_sure(X,Y) :-  not(denied(X,Y)),!, ask(X,Y).

  denied(X,Y) :-  db_denied(X,Y),!.

  remember(X,Y,'yes'):-  asserta(db_make_sure(X,Y)).
  remember(X,Y,'no'):- asserta(db_denied(X,Y)),  fail.

  clear_facts() :- retract(db_make_sure(_,_)),  fail.
  clear_facts() :- retract(db_denied(_,_)),  fail.

/* PRODUCTION RULES */

  test1(_M) :- it_is('mammal'),!.
  test1(_N).

  test2(_M,_C) :- it_is('carnivorous'),!.
  test2(_M,_N).
  test2(_N,_W) :- make_sure('does','swim'),!.
  test2(N,N).

  test3(_M, _C, _S) :- make_sure('has','stripes'), asserta(have_found('tiger')),!.
  test3(_M, _C, _N) :- asserta(have_found('cheetah')).
  test3(_M, _N, _L) :- not(make_sure('does','swim')), not(make_sure('does','fly')),!.
  test3(_M, N, N) :- asserta(have_found('blue whale')).
  test3(N, N, _F) :- make_sure('does','fly'), asserta(have_found('eagle')),!.
  test3(N, N, N) :- asserta(have_found('ostrich')).
  test3(_N, _W, _T) :- make_sure('has','tentacles'), asserta(have_found('octopus')),!.
  test3(N, _W, N).

  test4(_M, _N, _L, _S) :-  make_sure('has','stripes'), asserta(have_found('zebra')),!.
  test4(_M, N, _L, N) :- asserta(have_found('giraffe')).
  test4(N, _W, N, _F) :- make_sure('has','feathers'), asserta(have_found('penguin')),!.
  test4(N, _W, N, N) :- asserta(have_found('sardine')).

  it_is('mammal') :- make_sure('has','hair'),!.
  it_is('mammal') :- make_sure('does','give_milk'),!.

  it_is('carnivorous') :- make_sure('has','pointed_teeth'),!.
  it_is('carnivorous') :-  make_sure('does','eat_meat'),!.

  it_is('ungulate') :-  it_is('mammal'),
    make_sure('has','hooves'), make_sure('does','chew_cud'),!.

  it_is('bird') :- not(it_is('mammal')),
        make_sure('has','feathers'), make_sure('does','lay_eggs'),!.

   it_is('fish') :- make_sure('does','swim'), make_sure('has','fins'),!.

end implement program

我收到了以下错误:

The expression has type '::string', which is incompatible with the type '::symbol'
The flow pattern '(o)' does not exist for 'program::test1/1'    
The flow pattern '(o)' does not exist for 'program::test1/1'    

首先出错:

remember(X,Y,R)

0 个答案:

没有答案