Search code examples
prologdcg

Why are DCGs defined as a compact way to describe lists?


In my opinion, define the DCGs (Definite Clause Grammars) as a compact way to describe the lists in Prolog, is a poorly way to define them. As far as I know, the DCGs are not only used in Prolog, but also in other programming languages, such as Mercury.
In addition, they are called DCGs, because they represent a grammar in a set of definite clauses (Horn clauses), the basis of logic programming. So why if an entire Prolog program can be written using definite clauses, DCGs are solely defined as a compact way to describe the lists in Prolog?

Note: The doubt arises from the description for the tag given by SO.


Solution

  • The extended info from the DCG tag wiki provides additional information, which I think is both correct and also in close agreement with your first point:

    "DCGs are usually associated with Prolog, but similar languages such as Mercury also include DCGs."

    Regarding your second point: Emphasizing the close association with Prolog lists is in my opinion well justified, since a DCG indeed always describes a list, and typically also quite compactly.