

:- [fd].

:- import get_attr/3, put_attr/3 from machine.

/*
attv call / const success: test1 ; 1a has aliasing
attv call / attv success (aliasing) test2
var call / attv success test3
attv call / attv success (multiple table calls): test4

*/

% JW: Split test3t into test3ta and  test3tb. Disabled test3tb. See also
% general.P, test3. These seem to rely on the same misconception.

test:-
	test1,test1t,
	test1ta,
	test2,test2t,
	test3ta,
%	test3tb,
	writeln("test3t (clause 2): Atts = ([2,3])"),
	test4t, test5t.

test1:-
	put_attr(X,fd,[1,2,3]),
	p1(X),
	writeln('test1t: X = '(X)).

p1(X):- X = 3.

% tests nunify_with_numcon
test1t:-
	put_attr(X,fd,[1,2,3]),
	p1t(X),
	writeln('test1t: X = '(X)).

:- table p1t/1.

p1t(X):- X = 3.

%----------------

% tests unify_with_trie_numcon
test1ta:-
	put_attr(X,fd,[1,2,3]),
	p1t(Y), Y = X,
	writeln('test1ta: X = '(X)).

:- table p1ta/1.

p1ta(X):- X = 3.

%----------------

% tests unify (both cases).
test2:-
	put_attr(X,fd,[1,2,3]),
	p2(X),
	get_attr(X,fd,Atts),
	writeln('test2: Atts = '(Atts)).

p2(X):- put_attr(Y,fd,[2,3,4]), X = Y.

%----------------------

test2t:-
	put_attr(X,fd,[1,2,3]),
	p2t(X),
	get_attr(X,fd,Atts),
	writeln('test2t: Atts = '(Atts)).

:- table p2t/1.

p2t(X):- put_attr(Y,fd,[2,3,4]), X = Y.

%----------------
% tests unify_with_trie_attv
test3ta :-
	p3(X),
	get_attr(X,fd,Atts),
	writeln('test3t (clause 1): Atts = '(Atts)).
test3tb :-
	put_attr(X,fd,[1,2,3]),
	p3(X),
	get_attr(X,fd,Atts),
	writeln('test3t (clause 2): Atts = '(Atts)).

:- table p3/1.
p3(X):- put_attr(X,fd,[2,3,4]).

test4t:-
	put_attr(X,fd,[1,2,3]),
	t4t1(X),
	get_attr(X,fd,Atts),
	writeln('test4t: Atts = '(Atts)).

:- table t4t1/1, t4t2/1.
t4t1(X):-
	t4t2(X).

t4t2(X):-
	t4t1(X).
t4t2(X):- put_attr(X,fd,[2,3,4]).



test5t:-
	t5t1(X),
	get_attr(X,fd,Atts),
	writeln('test5t: Atts = '(Atts)).

:- table t5t1/1, t5t2/1.
t5t1(X):-
	t5t2(X),
	put_attr(Y,fd,[1,2,3]),
	Y = X.

t5t2(X):-
	t5t1(X).
t5t2(X):- put_attr(X,fd,[2,3,4]).
