% If one side is free (ie, undefined), assign to match the other side.
Unification is % essentially a combination of assignment and equality! It works as % follows: % If both sides are bound (ie, defined), check equality. % This is Prolog's central operation: unification. You can accept an earlier solution by pressing. Pressing again forces it to try % the last one, 42, after which it no longer accepts input because this % is the last solution. % By pressing in interactive mode you can reject that solution and % force it to assign the next one, 9. % Prolog makes magicNumber true by assigning one of the valid numbers to % the undefined variable Presto. Any name % starting with a capital letter is a variable in Prolog. % What makes Prolog unusual is that we can also tell Prolog to _make_ % magicNumber true, by passing it an undefined variable. % True % Some older Prologs may display "Yes" and "No" instead of True and % False. We can now use % interactive mode to ask if it is true for different values: ?- magicNumber ( 7 ). Note that % predicate names must start with lower case letters. % This introduces magicNumber as a predicate and says that it is true % with parameter 7, 9, or 42, but no other parameter. % As an example, here is a definition of the simplest kind of predicate: % a fact. % A command (called a goal) tells Prolog to make that state of the world % come true, if possible. % A subprogram (called a predicate) represents a state of the world. % Prolog is based on the ideal of logic programming. Different Prologs may behave % differently. % A bunch of errors and warnings will trigger when you load this file % due to the examples which are supposed to fail - they can be safely % ignored. % Lines that begin with ?- can be typed in interactive mode.
WIEDZMIN 2 PROLOG CODE
% This code must be loaded from a file to work as intended. % Prolog treats code entered in interactive mode differently % to code entered in a file and loaded ("consulted").