New library(macros) reply 1

Referring to the announcement.

Can these be used with DCGs?

Sure. It runs on top of module-local term expansion, so it is normally executed as the first transformation in the pipeline. DCG is the one-but-last step (followed by (dict) function evaluation).

Not really sure what would make it particularly attractive to DCGs though. The main usage identified so far are:

  • Document and abstract constants used in your code. We could always do so by writing these down as facts and use these. In practice this often seems to be just too much trouble for many people, and we often end up with such constants appearing literally in the code.
  • Simplify writing complex terms with a common pattern. That is why I wrote the library. Also for this problem there are often other solutions, but these didn’t feel appropriate here.
  • Get an easy way to generate terms at compile time. The alternative is typically to use term/goal expansion, but that easily becomes complicated.
1 Like