Prolog控制台在我运行脚本时崩溃



我一直在使用prolog,并多次在SWI控制台上运行不同的程序,但本周我遇到了一个程序,当我在mac上的控制台上以['Users/…./desktop/tiles']的形式运行它时。控制台在立即崩溃之前输出了5个错误,有人能告诉我为什么会发生这种情况吗?

jack(x,y).
:- writeln('   ').
:- writeln('>>>>>>>>>> *** Put har3.jpg into the working directory, then give goals ?- d,i. to start. *** <<<<<<<< ').
:- writeln('   ').
:- writeln('       >>    ... reading the COMMENTS in the PROGRAM also helps ... <<   ').
:- writeln('   ').
:- writeln('   ').
cl :-   free(@d),free(@mypic).   %clear, if I may apply a wild surmise to my own naming.
d  :-nl, write('Of course you can use any picture
as long as it is called har3.jpg ... '), nl,
write('.... and you put it where Prolog can find it.
Such as the working_directory... '),nl,nl, d1.
d1 :-              % d for do, I suppose.
new(@mypic,picture('R. Harmenszoon van Rijn' )),
send(@mypic, size, size(700,750)), % the default size is too small
send(@mypic,open),
new(I,image('har3.jpg')),    % use (local) variable I instead of
%         global @i
new(B,grbitmap(I,point(3,3),size(5,5),point(30,20))),
send(B,name(harmensz)),  % A rose by any other name... but we may have to
% find the chap, so we name him.
send(@mypic,display( B, point(400,70))).
i :- i(5,7).   % default intialization
i(Mx,My) :- get(@mypic,member(harmensz), Har),   % i for initialize
get(Har,image,I),
get(I,size,SI),
get(SI,width,SIW),
get(SI,height,SIH),
DX is floor((SIW-0)/Mx),write(':'),write(DX),
DY is floor((SIH-0)/My),write(DY),
new(@d,device),
send(@mypic,display(@d, point(70,70))),
make_alltiles( Mx,My,SIW,SIH,DX,DY,I),
send(Har,displayed(@off)),
% comment the line above out
% if you want leave the original jpg as a hint.
new(Box,box( @d?width, @d?height )),
send(@d,display,Box),
make_circles( Box,My,Mx),
scramble( Mx,My)
.
scramble(Mx,My) :- scramble( Mx,My,33).
scramble(_,_,0).
scramble(Mx,My,Count) :-
R is random( Mx+1),L is random( Mx+1),
U is random( My+1),D is random( My+1),
rmy(R),lm(L),   um(U),dm(D),
Count1 is Count-1,
scramble(Mx,My,Count1).
make_alltiles( Mx,My,SIW,SIH,DX,DY,I) :-
make_cols( Mx,My,SIW,SIH,DX,DY,I,Mx,My).
make_cols(0,_,_,_,_,_,_,_,_).
make_cols(C,My,SIW,SIH,DX,DY,I,Mx,My) :-
make_tiles( C,My,SIW,SIH,DX,DY,I,Mx,My),
C1 is C-1,
make_cols(C1,My,SIW,SIH,DX,DY,I,Mx,My).
make_tiles(_,0,_,_,_,_,_,_,_).
make_tiles(C,R,SIW,SIH,DX,DY,I,Mx,My) :-
C0 is C-1, R0 is R-1,
X is C0*DX, Y is R0*DY,
new(A,area(X,Y,DX,DY)),
get(I,clip,A,Itile),
new(Btile,grbitmap(Itile,point(C0,R0),size(Mx,My),point(DX,DY))),
send(@d,display( Btile, point(X,Y))),
make_tiles(C,R0,SIW,SIH,DX,DY,I,Mx,My).
%----------------------------------------
rmy(Row):- send(@d, for_all, tile, message(@arg1, move_r, Row)).
lm(Row):- send(@d, for_all, tile, message(@arg1, move_l, Row)).
um(Col):- send(@d, for_some, tile, message(@arg1, move_u, Col)).
dm(Col):- send(@d, for_some, tile, message(@arg1, move_d, Col)).

:- pce_begin_class( grbitmap, bitmap,"Bitmap that moves on a grid" ).
variable(grpoint, point, both, "Grid point at which Bitmap is displayed" ).
variable(grmax, size, both, "Number of grid rectangles (= grid points -1)"  ).
variable(grtile, point, both, "Size of the rectangular tiles" ).
initialise(DB, I:image=image, P:grpoint=point, M:grmax=size, T:grtile=point) :->
send(DB,send_super,initialise, I),  %first we initialise a plain bitmap
send(DB,grpoint,P),
send(DB,grmax,M),
send(DB,grtile,T),
send(DB,name,tile),
send(DB,recogniser,move_gesture(left)).
move_r(DB,Row) :-> get(DB,grpoint,P),get(P,y,Py), Py == Row.
move_r(DB,Row) :-> get(DB,grpoint,P), get(DB,grmax,M), get(DB,grtile,T),
get(M,width,Mx),get(P,x,Px),
X1 is Px+1, Px1 is X1 mod Mx,      %Px -1 for move_l
send(DB,grpoint,point(Px1,Row)),
get(T,x,Tx),get(T,y,Ty),
DisPx is Px1*Tx, DisPy is Row*Ty,
send(DB,move,point(DisPx,DisPy)).
move_l(DB,Row) :-> get(DB,grpoint,P),get(P,y,Py), Py == Row.
move_l(DB,Row) :-> get(DB,grpoint,P), get(DB,grmax,M), get(DB,grtile,T),
get(M,width,Mx),get(P,x,Px),
X1 is Px-1+Mx, Px1 is X1 mod Mx,      %Px +1 for move_r
send(DB,grpoint,point(Px1,Row)),     %
get(T,x,Tx),get(T,y,Ty),
DisPx is Px1*Tx, DisPy is Row*Ty,
send(DB,move,point(DisPx,DisPy)).

move_u(DB,Col) :-> get(DB,grpoint,P),get(P,x,Px), Px == Col.
move_u(DB,Col) :-> get(DB,grpoint,P), get(DB,grmax,M), get(DB,grtile,T),
get(M,height,My),get(P,y,Py),
Y1 is Py-1+My, Py1 is Y1 mod My,      %Py +1 for move_d
send(DB,grpoint,point(Col,Py1)),
get(T,x,Tx),get(T,y,Ty),
DisPx is Col*Tx, DisPy is Py1*Ty,
send(DB,move,point(DisPx,DisPy)).
move_d(DB,Col) :-> get(DB,grpoint,P),get(P,x,Px), Px == Col.
move_d(DB,Col) :-> get(DB,grpoint,P), get(DB,grmax,M), get(DB,grtile,T),
get(M,height,My),get(P,y,Py),
Y1 is Py+1, Py1 is Y1 mod My,      %Py -1 for move_u
send(DB,grpoint,point(Col,Py1)),
get(T,x,Tx),get(T,y,Ty),
DisPx is Col*Tx, DisPy is Py1*Ty,
send(DB,move,point(DisPx,DisPy)).


:- pce_end_class.
:- pce_begin_class( trcircle, circle,"we design our own button"  ).
variable(func,point,both, "1st: 1,2 for row,column
and 2nd: number of row or column, 0-based"  ).
initialise(C, Dia:diameter=int, Fun:func=point) :->
send(C,send_super,initialise, Dia),
send(C,colour,colour(black)),
send(C,fill_pattern, colour(yellow)),
send(C,slot,func,Fun),
send(C,recogniser, click_gesture(
left,'',single,
message(@prolog, fundl, /*@receiver*/C?func?x, /*@receiver*/C?func?y))),
send(C,recogniser,click_gesture(
right,'',single,
message(@prolog, funur, @receiver ?func?x, @receiver ?func?y))).
:- pce_end_class.
fundl(1,Y) :- lm(Y).   % Well, I guess one could rewrite and get rid of these
fundl(2,X) :- um(X).   % four lines
funur(1,Y) :- rmy(Y).
funur(2,X) :- dm(X).
make_circles(Box,R,C) :- make_rcircles( Box,R,C),make_bcircles( Box,R,C).
make_rcircles(Box,R,C) :- make_1rcircle( R,Box,R,C).
make_1rcircle( 0,_,_,_).
make_1rcircle( N,Box,R,C) :- get(Box,area,A),
get(A,height,Ah),get(A,x,Ax),get(A,y,Ay),get(A,width,Aw),
DY=floor((Ah)/(2*R)), N0 is N-1, Y is Ay + DY + N0*DY*2,
X is (Ax)+(Aw)+8,
new(TRC,trcircle(14,point(1,N0))),
send(TRC,center,point(X,Y)),
send(@d,display,TRC),
make_1rcircle(N0,Box,R,C).
make_bcircles(Box,R,C) :- make_1bcircle( C,Box,R,C).
make_1bcircle(0,_,_,_).
make_1bcircle(N,Box,R,C) :- get(Box,area,A),
get(A,height,Ah),get(A,x,Ax),get(A,y,Ay),get(A,width,Aw),
DX=floor((Aw)/(2*C)), N0 is N-1, X is Ax + DX + N0*DX*2,
Y is (Ay)+(Ah)+8,
new(TRC,trcircle(14,point(2,N0))),
send(@d,display,TRC),
send(TRC,center,point(X,Y)),
make_1bcircle(N0,Box,R,C).

这是我的剧本。

我看到的错误来自对未定义谓词的引用。将此添加为文件的第一行以修复这些问题:

:- use_module(library(pce)).

相关内容

  • 没有找到相关文章

最新更新