1/* Part of SWI-Prolog 2 Author: Douglas R. Miles, Jan Wielemaker 3 E-mail: logicmoo@gmail.com, jan@swi-prolog.org 4 WWW: http://www.swi-prolog.org http://www.logicmoo.org 5 Copyright (C): 2015, University of Amsterdam 6 VU University Amsterdam 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 You should have received a copy of the GNU General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 As a special exception, if you link this library with other files, 19 compiled with a Free Software compiler, to produce an executable, this 20 library does not by itself cause the resulting executable to be covered 21 by the GNU General Public License. This exception does not however 22 invalidate any other reasons why the executable file might be covered by 23 the GNU General Public License. 24*/ 25 26:- module(vprox, 27 []). 28 29 30match_existing_var(Var,Var0):- attvar(Var)->Var==Var0;(var(Var)->Var=Var0;Var=@=Var0). 31is_hprox_vprox(Var,Proxy):- is_hprox(Var,Proxy),!,is_vprox(Proxy,Var). 32 33 34is_vprox(Proxy):- get_attr(Proxy,vprox,vprox4(Proxy,_Serial,_Var,_)). 35is_vprox(Proxy,Var):- get_attr(Proxy,vprox,vprox4(Proxy,Var0,_Ser,_)),!,match_existing_var(Var,Var0). 36 37vprox(Proxy,Var):- is_vprox(Proxy,Var),!. 38vprox(Proxy,Var):- is_hprox_vprox(Var,Proxy),!. 39vprox(Proxy,Var):- gensym(vprox_,Serial),vprox(Proxy,Var,Serial,[vprox(Proxy,Var,Serial)]). 40 41vprox(Proxy,Var,Serial):-hprox(Var,Proxy,Serial,[vprox(Proxy,Var,Serial)]). 42 43% vprox(Proxy,Var,Serial,PrevGoals):- get_attrs(Var,Atts),!, put_attrs(Proxy,att(vprox,vprox4(Proxy,Var,Serial,Atts),Atts)). 44vprox(Proxy,Var,Serial,PrevGoals):- (var(Serial)->gensym(vprox_,Serial);true), hprox(Var,Proxy,Serial,PrevGoals). 45 46vproxattr_unify_hook(vprox4(_Proxy,Var,_Serial,_Atts),Value):- Var==Value,!. 47vproxattr_unify_hook(_InfoI,Value):- get_attr(Value,hprox,_),!. 48vproxattr_unify_hook(_InfoI,Value):- get_attr(Value,vprox,_),!. 49% ,throw((var:Var==value:Value , vprox:attr_unify_hook(vprox4(Proxy,Var,Serial,Atts),Value))). 50vproxattr_unify_hook(vprox4(Proxy,Var,Serial,Atts),Value):- nonvar(Value),!,throw((nonvar(Value) , vprox:attr_unify_hook(vprox4(Proxy,Var,Serial,Atts),Value))). 51vproxattr_unify_hook(vprox4(_Proxy,_Serial,_Var,_Atts),Value):- var(Value),!. 52vproxattribute_goals(Proxy)-->{get_attr(Proxy,vprox,vprox4(OrigProxy,Var,Serial,_))},({\+ is_hprox(Var,OrigProxy)}->[vprox(Proxy,Var,Serial)];[]). 53 54is_hprox(Var):- get_attr(Var,hprox,_). 55is_hprox(Var,Proxy):- get_attr(Var,hprox,hprox(_VarI,ProxyI,_PrevGoals)),match_existing_var(Proxy,ProxyI). 56 57hprox(Var):- hprox(Var,_Proxy,[hprox(Var)]). 58hprox(Var,Proxy):- is_hprox_vprox(Var,Proxy),!. 59hprox(Var,Proxy):- hprox(Var,Proxy,[hprox(Var,Proxy)]). 60hprox(Var,Proxy,PrevGoals):- gensym(hprox_,Serial),hprox(Var,Proxy,Serial,PrevGoals). 61 62hprox(Var,Proxy,Serial,PrevGoals):- 63 put_attr(Var,hprox,hprox(Var,Proxy,PrevGoals)), 64 dif(Var,Serial), 65 get_attrs(Var,Atts), 66 put_attrs(Proxy,att(vprox,vprox4(Proxy,Var,Serial,Atts),Atts)). 67 68hproxattribute_goals(Var)-->{get_attr(Var,hprox,hprox(OrigVar,_Proxy,Goals))},({OrigVar==Var}->;[]). 69hproxattr_unify_hook(hprox(_VarI,ProxyI,_GoalsI),Value):- (Value==ProxyI),!. 70hproxattr_unify_hook(_InfoI,Value):- get_attr(Value,hprox,_),!. 71hproxattr_unify_hook(_InfoI,Value):- get_attr(Value,vprox,_),!. 72hproxattr_unify_hook(hprox(_Var,Proxy,_Goals),Value):- 73 get_attrs(Proxy,Atts), 74 '$attvar':call_all_attr_uhooks(Atts, Value). 75/* 76 77hprox:attr_unify_hook(InfoI,Value):- get_attr(Value,hprox,InfoO), 78 InfoI=hprox(VarI,ProxyI,GoalsI),InfoI=hprox(VarI,ProxyI,GoalsI), 79 InfoO=hprox(VarO,ProxyO,GoalsO),InfoO=hprox(VarO,ProxyO,GoalsO), 80 get_attrs(ProxyI,AttsI), 81 '$attvar':call_all_attr_uhooks(AttsI, Value), 82 get_attrs(ProxyO,AttsO), 83 '$attvar':call_all_attr_uhooks(AttsO, ProxyI),!. 84 85hprox:attr_unify_hook(InfoI,Value):- get_attr(Value,hprox,InfoO), 86 InfoI=hprox(VarI,ProxyI,GoalsI),InfoI=hprox(VarI,ProxyI,GoalsI), 87 InfoO=hprox(VarO,ProxyO,GoalsO),InfoO=hprox(VarO,ProxyO,GoalsO), 88 copy_term(ProxyI,ProxyI,ProxyGoalsI),subst(ProxyGoalsI,VarI,ProxyI,CorrectedGoalsI), 89 copy_term(ProxyO,ProxyO,ProxyGoalsO),subst(ProxyGoalsO,VarO,ProxyO,CorrectedGoalsO), 90 maplist(call,CorrectedGoalsI), 91 maplist(call,CorrectedGoalsO), 92 append(GoalsI,GoalsO,Goals), 93 list_to_set(Goals,GoalsSet), 94 setarg(3,InfoI,GoalsSet), 95 setarg(3,InfoO,GoalsSet). 96*/ 97 98% ?- hprox(X,PX),hprox(Y,PY),X=Y. 99 100 101:- fixup_exports.