{"title":"The Semantics of Metapropramming in Prolog","authors":"David S. Warren","doi":"arxiv-2408.07652","DOIUrl":null,"url":null,"abstract":"This paper describes a semantics for pure Prolog programs with negation that\nprovides meaning to metaprograms. Metaprograms are programs that construct and\nuse data structures as programs. In Prolog a primary mataprogramming construct\nis the use of a variable as a literal in the body of a clause. The traditional\nProlog 3-line metainterpreter is another example of a metaprogram. The account\ngiven here also supplies a meaning for clauses that have a variable as head,\neven though most Prolog systems do not support such clauses. This semantics\nnaturally includes such programs, giving them their intuitive meaning. Ideas from M. Denecker and his colleagues form the basis of this approach.\nThe key idea is to notice that if we give meanings to all propositional\nprograms and treat Prolog rules with variables as the set of their ground\ninstances, then we can give meanings to all programs. We must treat Prolog\nrules (which may be metarules) as templates for generating ground propositional\nrules, and not as first-order formulas, which they may not be. We use\nparameterized inductive definitions to give propositional models to Prolog\nprograms, in which the propositions are expressions. Then the set of\nexpressions of a propositional model determine a first-order Herbrand Model,\nproviding a first-order logical semantics for all (pure) Prolog programs,\nincluding metaprograms. We give examples to show the applicability of this theory. We also\ndemonstrate how this theory makes proofs of some important properties of\nmetaprograms very straightforward.","PeriodicalId":501197,"journal":{"name":"arXiv - CS - Programming Languages","volume":null,"pages":null},"PeriodicalIF":0.0000,"publicationDate":"2024-08-14","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"arXiv - CS - Programming Languages","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/arxiv-2408.07652","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0
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 M. 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.