[m-users.] A predicate taking a lists of predicates as input?

Tomas By tomas at basun.net
Thu Sep 25 02:58:55 AEST 2025


On Wed, 24 Sep 2025 18:47:01 +0200, Volker Wysk wrote:
> Am Mittwoch, dem 24.09.2025 um 18:40 +0200 schrieb Tomas By:
> > No, but there are better ways to implement a parser.
> Now you've made me curious. Do you have a catchword which I could look up?


https://en.wikipedia.org/wiki/Continuation-passing_style

Essentially, you have a series of preds where each one handles some
small bit of the syntax and then calls the next one passing along the
data so far. At the end you return the complete result, and each
predicate can also return an error instead of calling.

This is (more or less) how Mercury itself is implemented, I believe.

It gives you much better control over error messages, and it goes very
well together with literate programming as you can mix the relevant
parts of the parser with documentation and error code.

/Tomas


More information about the users mailing list