1

I've been stuck for quite some time on this issue, my Prolog program has the following line within its operator definitions:

:- op(100, xfx, [has,gives,'does not',eats,lays,isa]).

and then this fact:

fact :: X isa animal :-
     member(X, [cheetah,tiger,giraffe,zebra,ostrich,penguin, albatross]).

When I try to use the operator It says it is undefined and I just do not understand why.

?- peter isa tiger.
ERROR: [Thread pdt_console_client_0_Default Process] toplevel: Undefined  
procedure: (isa)/2 (DWIM could not correct goal)

Sorry if its something silly (which it probably is) but I am new to Prolog. Any help is much appreciated.

repeat
  • 18,496
  • 4
  • 54
  • 166
Reddy
  • 481
  • 1
  • 7
  • 20
  • It works exactly as expected if you just remove `fact ::`. To define a rule in Prolog, use `Head :- Body.`, for example: `X isa animal :- member(...).`. – mat Dec 06 '15 at 17:38

1 Answers1

3

It is working. See for yourself:

    stefan@stefan-Lenovo-G510 ~ $ swipl
    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.12)
    % ...

    ?- op(100, xfx, [has,gives,'does not',eats,lays,isa]).
    true.

    ?- Term = (peter isa tiger).
    Term = peter isa tiger.

The error message that you got ...

    procedure: (isa)/2 (DWIM could not correct goal)

... says that too!

Is it clearer now?

repeat
  • 18,496
  • 4
  • 54
  • 166
  • 1
    Oh okay so you have to store it in a variable for it to work? I am trying to develop an expert system that begins to ask questions after I state that peter isa tiger so I'm not sure how I can make that work without the 'Term =' preceding it. – Reddy Dec 06 '15 at 16:53
  • 1
    It works without `Term = ...` if you have a predicate `(isa)/2`. You can add to that definition on the [tag:prolog-toplevel] like this: `?- assert(peter isa tiger).` **Then** you can ask `?- peter isa X.`. Let's add one more: `?- assert(peter isa male).` And ask again: `?- peter isa Y.` I get the answer `X = tiger ; X = male`. – repeat Dec 06 '15 at 17:01
  • 1
    Okay this is making much more sense to me, although I am trying to make the commands somewhat user-friendly so is there a way I can make `peter isa tiger` work without assert() as well? – Reddy Dec 06 '15 at 17:07
  • 1
    Directly in the [tag:prolog-toplevel]? No. `X isa Y` **is** a valid goal to ask. To tell, use [tag:prolog-assert]. – repeat Dec 06 '15 at 17:17
  • 1
    @user2023740. If you're aiming at implementing an expert system, designing and implementing the REPL / toplevel / shell is important and should be tailored to the concrete use-cases you have in mind. – repeat Dec 06 '15 at 17:27