From the hub, tagged: "DCG"
Prolog is rather popular for Expert Systems. Why? Well because it's homoiconic and because we have DCG's, we can reify a query to make it explain itself. That's a lot of jargon, in this post we'll break it down and make some explanations.
Definite Clause Grammars (DCGs) provide a useful threading state abstraction with countless applications in Logtalk and Prolog programming. But programmers sometimes break this abstraction without realizing it and for no benefit. This usually happens when ...
I work in an industry that likes to use an ID/label/hyperlink notation by combining a letter denoting a parent class with a number: "H-1". The application I'm working on, given a parent class, needs to return the next ID. This shouldn't be too hard if they were sequential, but ID's can be deleted and so the next available ID needs to be returned. In this post, we explore how a DCG can be used to solve this problem.
What are DCGs and what are "extended" DCGs?
One of my favourite features of Prolog are DCGs, or Definite Clause Grammars.
Markus Triska has a nice tutorial on them, but the quick pitch is they’re basically built-in syntax for writing parsers. Forget regular expressions – in Prolog it’s just as easy to write a full-on grammar!