-2

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?

jipthechip
  • 157
  • 1
  • 13
  • It's probably a good idea not to be too careless with spaces around terms in Prolog; `goal( 2, 3 )` works, but `goal (2, 3)` does not parse. – Daniel Lyons Apr 10 '19 at 03:20

1 Answers1

1

I figured out that the issue was I needed to go to File and Consult ... and select test0.pl. After that, the queries gave their expected results.

jipthechip
  • 157
  • 1
  • 13
  • You can accept your own answer by clicking the check mark to the left of this answer. Nice job on figuring it out on your own. – Guy Coder Apr 09 '19 at 23:33