Prolog 谓词调用 [英] Prolog predicate calling
问题描述
在以下教程中:http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/7_3.html
有一部分:
test_parser :- repeat,
write('?? '),
read_line(X),
( c(F,X,[]) | q(F,X,[]) ),
nl, write(X), nl, write(F), nl, fail.
现在我对 c(F,X,[]) 和 q(F,X,[]) 部分感到非常困惑,因为它似乎与我见过的任何东西都不匹配,c 只需要一个参数从我可以告诉和这些参数似乎对 q 没有意义.请帮助我了解这里发生了什么.
Now I'm extremely confused about the c(F,X,[]) and q(F,X,[]) part because it doesn't seem to match any thing that I have seen, c only takes one parameter from what I can tell and these parameters don't seem to make sense for q. Please help me understand what is going on here.
推荐答案
c
是用 -->
定义的,它实际上添加了两个隐藏参数.其中第一个是要由语法规则解析的列表;第二个是解析后的剩下的".c(F,X,[])
调用列表X
上的c
得到结果F
,期望[]
保留,即解析器应该使用整个列表 X
.
c
is defined with -->
, which actually adds two hidden arguments to it. The first of these is a list to be parsed by the grammar rule; the second is "what's left" after the parse. c(F,X,[])
calls c
on the list X
to obtain a result F
, expecting []
to be left, i.e. the parser should consume the entire list X
.
这篇关于Prolog 谓词调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!