[英]Prolog recursion and stack issue
I'm trying to test out recursion in prolog. 我正在尝试在序言中测试递归。 Based on the KB and conditional statements below, I tried to make a recursive call and wanted to use the one specifically for "eastOf(X,Y) :- westOf(X,Z),eastOf(Z,Y)" The query I am using is "eastOf(ave,yonge)" which should use that recursive call and state that X is ave, Y is yonge and Z is collegePark.
根据下面的KB和条件语句,我尝试进行递归调用,并希望将其专门用于“ eastOf(X,Y):-westOf(X,Z),eastOf(Z,Y)”查询I我正在使用的是“ eastOf(ave,yonge)”,它应该使用该递归调用,并声明X为ave,Y为yonge和Z为collegePark。 However the proglog program i am using current (ECliPSe) iss giving me this error "*** Overflow of the local/control stack! You can use the "-l kBytes" (LOCALSIZE) option to have a larger stack. Peak sizes were: local stack 11024 kbytes, control stack 120048 kbytes"
但是,我使用的当前proglog程序(ECliPSe)会给我这个错误“ ***本地/控制堆栈溢出!您可以使用“ -l kBytes”(LOCALSIZE)选项设置一个较大的堆栈。 :本地堆栈11024 KB,控制堆栈120048 KB”
Find below my .pl file 在我的.pl文件下面找到
eastOf(collegePark,yonge).
eastOf(sushi,eaton).
eastOf(X,Y) :- westOf(Y,X).
eastOf(X,Y) :- westOf(X,Z), eastOf(Z,Y).
westOf(ellington,yonge).
westOf(ryerson,sushi).
westOf(ave,collegePark).
westOf(X,Y) :- eastOf(Y,X).
westOf(X,Y) :- eastOf(X,Z), westOf(Z,Y).
I think you meant to use eastOf(yonge,collegePark)
as your first statement. 我认为您打算使用
eastOf(yonge,collegePark)
作为您的第一条声明。 Right now it never finds an atomic statement starting with either 'ave' or 'yonge', and keeps looping between eastOf(X,Y) :- westOf(Y,X)
and westOf(X,Y) :- eastOf(Y,X)
. 现在,它永远找不到以'ave'或'yonge'开头的原子语句,并且在
eastOf(X,Y) :- westOf(Y,X)
和westOf(X,Y) :- eastOf(Y,X)
。
eastOf(X,Y) :- westOf(Y,X).
westOf(X,Y) :- eastOf(Y,X).
The infinite loop has occurred in the combination of these two predicates. 这两个谓词的组合发生了无限循环。 Even if stack size is large, size over occurs.
即使堆栈大小很大,也会发生尺寸过大的情况。 I change your program as follows.
我如下更改程序。
eastOf_data(collegePark,yonge).
eastOf_data(sushi,eaton).
eastOf(X,Y) :- westOf_data(Y,X).
eastOf(X,Y) :- westOf_data(X,Z), eastOf_data(Z,Y).
westOf_data(ellington,yonge).
westOf_data(ryerson,sushi).
westOf_data(ave,collegePark).
westOf(X,Y) :- eastOf_data(Y,X).
westOf(X,Y) :- eastOf_data(X,Z), westOf_data(Z,Y).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.