% Define parent-child relationships
parent(alice, bob).

% Define a rule to perform unification
unify_predicate(Y) :-
    parent(alice, bob),      % First predicate
    parent(alice, Y).        % Second predicate with a variable

% Main function to perform the query and print the result
main :-
    unify_predicate(Y),
    write('Unify Y = '), write(Y), nl.

% Test case for unification
test_unification :-
    main.

% Test case for failure when parent/3 is used
test_failure :-
    \+ (parent(alice, _, _) ; parent(_, _, alice)),
    write('Unification failed'), nl.

% Initialization directive for the unification test case
:- initialization(test_unification).

% Initialization directive for the failure test case
:- initialization(test_failure).

 

Prolog Online Compiler

Write, Run & Share Prolog code online using OneCompiler's Prolog online compiler for free. It's one of the robust, feature-rich online compilers for Prolog language. Getting started with the OneCompiler's Prolog editor is easy and fast. The editor shows sample boilerplate code when you choose language as Prolog and start coding.