I'm new to Prolog and I'm having trouble figuring out why it's telling me procedures are undefined when I query them, when they appear to be defined. This code was given to me by my instructor and I'm not allowed to change it, so it must be a problem with the way I'm compiling it or something related to that. I'm using the SWI-Prolog IDE.
I have 2 .pl files:
print-maze.pl:
printMaze() :- boundary(XMAX,YMAX), \+printMaze( p(-1,YMAX), XMAX ).
printMaze( p( _, Y ), _ ) :- Y < -1, fail.
printMaze( p( X, Y ), XMAX ) :- Y >= -1, X > XMAX,
nl,
NewY is Y - 1,
printMaze( p(-1,NewY), XMAX ).
printMaze( p( X, Y ), XMAX ) :- Y >= -1, X =< XMAX,
printSpot( X, Y ),
NewX is X + 1,
printMaze( p(NewX,Y), XMAX ).
printSpot( X, Y ) :- (
( X is -1, Y is -1 );
( boundary( X, _ ), Y is -1 );
( boundary( _, Y ), X is -1 );
boundary( X, Y )
),
!, write( '+' ).
printSpot( X, Y ) :- ( boundary( X, _ ); X = -1 ),
!, N is Y mod 10, write( N ).
printSpot( X, Y ) :- ( boundary( _, Y ); Y = -1 ),
!, N is X mod 10, write( N ).
printSpot( X, Y ) :- goal( X, Y ), !, write( '*' ).
printSpot( X, Y ) :- wall( X, Y ), !, write( '-' ).
printSpot( _, _ ) :- write( ' ' ).
and test0.pl:
goal( 2, 2 ).
boundary( 3, 3 ).
wall( 0, 1 ).
wall( 0, 2 ).
wall( 2, 0 ).
wall( 2, 1 ).
% 0,0
% 2,2
:- load_files( 'print-maze.pl' ).
After clicking Compile
and then Make
in the editor while I have both files open,
when I do the query:
?- goal(2,2).
I get the error:
ERROR: Undefined procedure: goal/2 (DWIM could not correct goal)
and when I do the query:
?- printMaze().
I get the error:
ERROR: Undefined procedure: boundary/2
ERROR: In:
ERROR: [9] boundary(_7002,_7004)
ERROR: [8] printMaze at c:/users/jproc/documents/prolog/print-maze.pl:7
ERROR: [7] <user>
goal/2
and boundary/2
appear to be defined in test0.pl
, so what gives?