Hostname: page-component-89b8bd64d-4ws75 Total loading time: 0 Render date: 2026-05-08T05:45:12.990Z Has data issue: false hasContentIssue false

The Semantics of Metaprogramming in Prolog

Published online by Cambridge University Press:  15 January 2025

DAVID SCOTT WARREN*
Affiliation:
Stony Brook University, Stony Brook, NY, USA (e-mail: warren@cs.stonybrook.edu) XSB Inc., Setauket, NY, USA (e-mail: warren@xsb.com)
Rights & Permissions [Opens in a new window]

Abstract

This paper describes a semantics for pure Prolog programs with negation that provides meaning to metaprograms. Metaprograms are programs that construct and use data structures as programs. In Prolog a primary mataprogramming construct is the use of a variable as a literal in the body of a clause. The traditional Prolog 3-line metainterpreter is another example of a metaprogram. The account given here also supplies a meaning for clauses that have a variable as head, even though most Prolog systems do not support such clauses. This semantics naturally includes such programs, giving them their intuitive meaning. Ideas from Denecker and his colleagues form the basis of this approach. The key idea is to notice that if we give meanings to all propositional programs and treat Prolog rules with variables as the set of their ground instances, then we can give meanings to all programs. We must treat Prolog rules (which may be metarules) as templates for generating ground propositional rules, and not as first-order formulas, which they may not be. We use parameterized inductive definitions to give propositional models to Prolog programs, in which the propositions are expressions. Then the set of expressions of a propositional model determine a first-order Herbrand Model, providing a first-order logical semantics for all (pure) Prolog programs, including metaprograms. We give examples to show the applicability of this theory. We also demonstrate how this theory makes proofs of some important properties of metaprograms very straightforward.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2025. Published by Cambridge University Press
Figure 0

Fig. 1. Venn diagram for sets determined by rules $\mathcal{P}$.

Figure 1

Fig. 2. Venn diagram for sets determined by parameterized $\mathcal{P}$.

Figure 2

Fig. 3. Venn diagram for sets of parameterized $\mathcal{P}$ with negation.