Subject: [SWIPL] Vars/4

From: "Douglas R. Miles" <[email-masked]>
Date: Sat, 10 Feb 2001 03:55:12 -0800

Hello,

I having troubles picking out Variables

it is not picking up on _h4736 for some reason. 

   (3) Call:
vars(and(isa(_h4729,'MilitaryEvent'),performedBy(_h4729,_h4736),maleficiary(
_h4729,'Kuwait'),isa(_h4736,'IndependentCountry'),different(_h4736,'Kuwait')
,
	temporallySubsumes('PersianGulfWar',_h4729)),_h5746,_h5742,_h5743) ?

   (3) Exit:
vars(and(isa(_h4729,'MilitaryEvent'),performedBy(_h4729,_h4736),maleficiary(
_h4729,'Kuwait'),isa(_h4736,'IndependentCountry'),different(_h4736,'Kuwait')
,
	temporallySubsumes('PersianGulfWar',_h4729)),[_h4729],[_h4729],[]) ?

I would expect the output to be instead...

   (3) Exit:
vars(and(isa(_h4729,'MilitaryEvent'),performedBy(_h4729,_h4736),maleficiary(
_h4729,'Kuwait'),isa(_h4736,'IndependentCountry'),different(_h4736,'Kuwait')
,
	
temporallySubsumes('PersianGulfWar',_h4729)),[_h4729,_h4736],[],[_h4729,_h47
36]) ?

What am I doing wrong?

I am using this definition Vars/4.. but for some reason not working in XSB

% ===================================================================
% vars/4.
% ===================================================================

vars(Term, Vars, Singletons, Multiples) :-
    vars(Term, VarList, []),
    close_list(VarList),
    keysort(VarList, KeyList),
    split_key_list(KeyList, Vars, Singletons, Multiples).

close_list([]):-!.
close_list([_]):-!.
close_list([_,_]):-!.
close_list([_,_|CLOSE]):-!,close_list(CLOSE).
close_list([_,_,_|CLOSE]):-!,close_list(CLOSE).
close_list([_,_,_,_|CLOSE]):-!,close_list(CLOSE).
close_list([_,_,_,_,_|CLOSE]):-!,close_list(CLOSE).
close_list([_,_,_,_,_,_|CLOSE]):-!,close_list(CLOSE).

open_list(A,B):-!,append(A,_,B).

split_key_list([], [], [], []).
split_key_list([V-_,W-_|Vs], Vars, Singletons, Multiples) :- W == V, !,
    Vars = [V|Vars1],
    Multiples = [V|Multiples1],
    split_key_list(Vs, V, Vs1),
    split_key_list(Vs1, Vars1, Singletons, Multiples1).
split_key_list([V-_|Vs], [V|Vars], [V|Singletons], Multiples) :-
    split_key_list(Vs, Vars, Singletons, Multiples).

split_key_list([W - _|Vs], V, Vs1) :- W == V, !,
    split_key_list(Vs, V, Vs1).
split_key_list(Vs1, _, Vs1).

vars(Term, V0, V) :-
    (	var(Term) -> (V0 = [Term - x|V])	% Note this change.
    ;   functor(Term, _, N),
        vars(1, N, Term, V0, V)
    ).
    
vars(I, N, Term, V0, V) :-
    (   (I > N) -> true
    ;   arg(I, Term, Arg),
	vars(Arg, V0, V1),
	J is I + 1,
	vars(J, N, Term, V1, V)
    ).

gratefully,
	Douglas