Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined Procedure in SWI-Prolog does not work

I am just starting to use Prolog, and already I've run into problem with a seemingly simple example. Here is my .pl file:

hacker(P) :- mountaindew(P), doesntsleep(P).
hacker(P) :- writesgoodcode(P).
writesgoodcode(jeff).

Then, after I load the program into swipl, I test it with this line at the prompt

writesgoodcode(jeff).

I thought it would display true, but I get this error:

?- hacker(jeff).
ERROR: hacker/1: Undefined procedure: mountaindew/1
   Exception: (7) hacker(jeff) ? 

This program works fine, but this doesn't solve my problems:

hacker(P) :- writesgoodcode(P).
writesgoodcode(jeff).

$ swipl -s dumb.pl
% dumb.pl compiled 0.00 sec, 1,112 bytes

?- hacker(jeff).
true.

Can anyone explain why my original program doesn't work? From my understanding, Prolog should "skip" the first statement since it doesn't have enough information, and check the next line. It does have enough info for that second line, and thus it should evaluate true. Any help or a point in the right direction would be great. Thanks.

like image 873
Matt Avatar asked Oct 11 '22 02:10

Matt


1 Answers

As the error message says, you have an undefined procedure mountaindew/1. To make your code return true, your options are:

  1. Define this predicate
  2. Declare that this predicate is dynamic: dynamic(mountaindew/1)
  3. Declare that all unknown predicates should fail (not recommended): set_prolog_flag(unknown, fail)
like image 74
Kaarel Avatar answered Nov 17 '22 00:11

Kaarel