Prolog predicate calling

二次信任 提交于 2019-12-06 09:12:10

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.

c//1 and q//1 are entry points (aka top level production) of the Definite Clauses Grammar defined below, where you find

c(F) --> ....
q(F) --> ....

This style of 'call' on a DCG entry point is discouraged, usually is better to invoke the phrase(Grammar, TextToAnalyze, TextAfterAnalysis), in this case phrase((c(F) ; q(F)), "some text", "")...

The --> operator is usually rewritten adding 2 arguments, that are cause of your concern.

EDIT

I.e. c(L) --> lead_in,arrange(L),end.

is rewritten to

c(L,X,Y) :- lead_in(X,X1),arrange(L,X1,X2),end(X2,Y).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!