Inverted syntax: Difference between revisions

Line 851:
<pre>
Thank God it's Friday!
</pre>
 
=={{header|Prolog}}==
Prolog programs are made up of facts and rules. Facts are considered "true" if they are provable from the source code and "false" otherwise. The rules for proving new facts are described using "horn clauses" which are backwards "if" statements: the truth value of the second part becomes the truth value of the first part.
 
The facts themselves are usually expressed using "functors" involving parentheses, with the constant in front of the parentheses naming some property which applies to one or more items inside. As a result, they sometimes kind of look like backwards "is" statements.
 
<lang prolog>% Dracula is a vampire.
% Also, you become a vampire if someone who is a vampire bites you.
vampire(dracula).
vampire(You) :- bites(Someone, You), vampire(Someone).
 
% Oh no! Dracula just bit Bob...
bites(dracula, bob).</lang>
 
{{out}}
We load the source code into the interpreter and ask whether Alice and Bob are vampires...
<pre>
?- vampire(alice).
false.
 
?- vampire(bob).
true .
</pre>
 
Anonymous user