Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Logic programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Metalogic programming=== [[Metaprogramming]], in which programs are treated as data, was already a feature of early Prolog implementations.<ref>Colmerauer, A. and Roussel, P., 1996. The birth of Prolog. In History of programming languages---II (pp. 331-367).</ref><ref name="Warren">Warren, D.H., Pereira, L.M. and Pereira, F., 1977. Prolog-the language and its implementation compared with Lisp. ACM SIGPLAN Notices, 12(8), pp.109-115.</ref> For example, the Edinburgh DEC10 implementation of Prolog included "an interpreter and a compiler, both written in Prolog itself".<ref name="Warren"/> The simplest metaprogram is the so-called "[[Vanilla (computing)|vanilla]]" meta-interpreter: <syntaxhighlight lang="prolog"> solve(true). solve((B,C)):- solve(B),solve(C). solve(A):- clause(A,B),solve(B). </syntaxhighlight> where true represents an empty conjunction, and (B,C) is a composite term representing the conjunction of B and C. The predicate clause(A,B) means that there is a clause of the form A :- B. Metaprogramming is an application of the more general use of a ''[[metalogic]]'' or ''[[metalanguage]]'' to describe and reason about another language, called the ''object language''. Metalogic programming allows object-level and metalevel representations to be combined, as in natural language. For example, in the following program, the atomic formula <code>attends(Person, Meeting)</code> occurs both as an object-level formula, and as an argument of the metapredicates <code>prohibited</code> and <code>approved.</code> <syntaxhighlight lang="prolog"> prohibited(attends(Person, Meeting)) :- not(approved(attends(Person, Meeting))). should_receive_sanction(Person, scolding) :- attends(Person, Meeting), lofty(Person), prohibited(attends(Person, Meeting)). should_receive_sanction(Person, banishment) :- attends(Person, Meeting), lowly(Person), prohibited(attends(Person, Meeting)). approved(attends(alice, tea_party)). attends(mad_hatter, tea_party). attends(dormouse, tea_party). lofty(mad_hatter). lowly(dormouse). ?- should_receive_sanction(X,Y). Person = mad_hatter, Sanction = scolding. Person = dormouse, Sanction = banishment. </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)