I am in the process of learning prolog and have found the expression call(eos)
in documents and libraries (I understand that it serves the function of identifying the end of a list in a dcg). I don’t understand why it’s called in the expression call(eos)
, instead of just eos
.
For example, in the book “The power of prolog” this expression is used in the following example:
lines([]) --> call(eos), !.
lines([L|Ls]) --> line(L), lines(Ls).
line([]) --> ( "\n" | call(eos) ), !.
line([C|Cs]) --> [C], line(Cs).
eos([], []).
If I try to write the predicates like this:
lines([]) --> eos, !.
lines([L|Ls]) --> line(L), lines(Ls).
line([]) --> ( "\n" | eos ), !.
line([C|Cs]) --> [C], line(Cs).
eos([], []).
And run both versions on swi with some basic examples, I get the same results. Looking at the listing, the only difference in the translation of the dcg is between the expression: call(eos,A,B) and eos(A,B) which I understand are equivalent. Is there a reason why call(eos) is used instead of the simpler alternative? Maybe other prolog implementations treat dcgs separately and don’t allow the eos call, needing to be referenced via call/1?