ychr-0.1.0.0: test/golden/copy_term_sharing/copy_term_sharing.chr
:- module(copy_term_sharing, [shared/2, non_shared/3, ground_copy/1, nested_copy/1]).
:- use_module(prelude).
:- chr_constraint shared/2, non_shared/3, ground_copy/1, nested_copy/1.
% Sharing: the copy of f(X, X) is f(Y, Y) with Y shared. Binding the
% copy's first arg to 1 must propagate to its second arg via R.
shared(X, R) <=>
C is copy_term(quote(f(X, X))),
C = f(1, R).
% Non-sharing: the copy of f(X, Y) is f(Y1, Y2) with distinct vars.
% Binding only the first arg of the copy leaves R unbound.
non_shared(X, Y, R) <=>
C is copy_term(quote(f(X, Y))),
C = f(1, R).
% Ground term copy: structure preserved verbatim.
ground_copy(R) <=>
R is copy_term(quote(p(1, foo, [a, b]))).
% Nested ground copy.
nested_copy(R) <=>
R is copy_term(quote(t1(t2(t3(42))))).