nsacaddy.blogg.se

Visual prolog ejemplos
Visual prolog ejemplos












% False % First acts as assignment and binds X=3 % Second acts as equality because X is bound % Since 3 does not equal 2, gives False % Thus in Prolog variables are immutable ?- X = 3 + 2. % X = Y = 2 - two assignments % Note Y is assigned too, even though it is % on the right hand side, because it is free ?- X = 3, X = 2. % % The = sign in Prolog represents unification, so: ?- 2 = 3. With some luck, % one of the two sides will eventually be bound, but this isn't % necessary. % If both sides are free, the assignment is remembered. % 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.

visual prolog ejemplos

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.

visual prolog ejemplos

% 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.

visual prolog ejemplos

% 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. % 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").














Visual prolog ejemplos