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!
=== Relationship with functional programming === {{See also|Functional programming#Comparison to logic programming}} Logic programming can be viewed as a generalisation of functional programming, in which functions are a special case of relations.<ref name=dis>{{cite book|author1=Daniel Friedman|author2=William Byrd|author3=Oleg Kiselyov|author4=Jason Hemann|title=The Reasoned Schemer, Second Edition|year=2018|publisher=The MIT Press}}</ref> For example, the function, mother(X) = Y, (every X has only one mother Y) can be represented by the relation mother(X, Y). In this respect, logic programs are similar to [[relational databases]], which also represent functions as relations. Compared with relational syntax, functional syntax is more compact for nested functions. For example, in functional syntax the definition of maternal grandmother can be written in the nested form: <syntaxhighlight lang="prolog"> maternal_grandmother(X) = mother(mother(X)). </syntaxhighlight> The same definition in relational notation needs to be written in the unnested, flattened form: <syntaxhighlight lang="prolog"> maternal_grandmother(X, Y) :- mother(X, Z), mother(Z, Y). </syntaxhighlight> However, nested syntax can be regarded as syntactic sugar for unnested syntax. [[Ciao (programming language)|Ciao]] Prolog, for example, transforms functional syntax into relational form and executes the resulting logic program using the standard Prolog execution strategy.<ref>A. Casas, D. Cabeza, M. V. Hermenegildo. A Syntactic Approach to Combining Functional Notation, Lazy Evaluation and Higher-Order in LP Systems. The 8th International Symposium on Functional and Logic Programming (FLOPS'06), pages 142-162, April 2006.</ref> Moreover, the same transformation can be used to execute nested relations that are not functional. For example: <syntaxhighlight lang="prolog"> grandparent(X) := parent(parent(X)). parent(X) := mother(X). parent(X) := father(X). mother(charles) := elizabeth. father(charles) := phillip. mother(harry) := diana. father(harry) := charles. ?- grandparent(X,Y). X = harry, Y = elizabeth. X = harry, Y = phillip. </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)