Question on the use of eos and call(eos) in DCGs

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?

But what about this :slight_smile:

4 ?- phrase(("a",eos), List, Tail).
List = [97],
Tail = [].

I don’t know how useful eos//0 is in generative grammars. Anyway, you can use SWI-Prolog’s eos//0 simply as eos, without call.

Using \+/1 typically does not improve “declarativeness”. I’d consider your solution more like a way to stay within the DCG standard (has this been approved?) I see little problem for an implementation to provide an eos//0 in a library that is compatible with how it translates DCGs. If you want a portable library, write this in the library and hope the compiler will do its work.

eos --> call(eos_).

eos_([],[]).