Re: [eclipse-clp-users] Copying Eclipse Data / Re: OutOfProcessEclipse Error

From: Christian Wirth <tyrion_at_...215...>
Date: Thu, 24 Jun 2010 17:45:08 +0200
I'm trying to copy a nested term structure (a list and a tree).
When exporting the term structure, i replace all prolog-variables with 
strings by term_string
When importing, those strings get replaces back with a variable and all 
variables of the same string are getting unified ... but i have an error 
somewhere in the program that prevents the variable unification.
Meaning that when variable A gets replaced by a constant, other 
occurances of A are not getting replaced ?
I know the same variable name does not mean that it is the same 
variable, but that should be done by string_to_var, because if the 
string has already a replacement var, this var gets returned.

Sourcecode (for the list version):
loadConvert(List,Tree) :- varToConstRecList(List).
saveConvert(List,Tree) :- init,constToVarRecList(List).


init :- 
(current_predicate(logicStorage/2)->retractall(logicStorage(_,_));true),assertz(logicStorage(_,_):-false).

% if string is seen, return variable (should unify all occurances of the 
same string)
string_to_var(String,Var) :- logicStorage(String,Var),!.
string_to_var(String,Var) :- 
term_string(Var,String),assert(logicStorage(String,Var)).

varToConstRecList([]) :- !.
varToConstRecList([[Index,Head:-Body]|Rest]) :- 
replace(Head),replace(Body),varToConstRecList(Rest).

replace(F/A) :- !. %entry is only functor/arity
replace(Term) :- is_list(Term),(foreach(X,Term) do 
(var(X)->true;replace(X))),!. %entry is a list
replace(Term) :- functor(Term,F,A),(for(I,1,A),param(Term) 
do(arg(I,Term,Arg),getReplace(Arg,Replace),setarg(I,Term,Replace))). 
%entry is a term

getReplace(Var,Replace) :- var(Var),term_string(Var,Replace),!. %arg is 
a var then replace
getReplace(Var,Replace) :- replace(Var),Replace=Var. %arg is no var then 
try list and term


constToVarRecList([]) :- !.
constToVarRecList([[Index,Head:-Body]|Rest]) :- 
replaceBack(Head),replaceBack(Body),constToVarRecList(Rest).

replaceBack(Var) :- var(Var),!.
replaceBack(Term) :- is_list(Term),(foreach(X,Term) do 
(var(X)->true;replaceBack(X))),!.
replaceBack(Term) :- functor(Term,F,A),(for(I,1,A),param(Term) 
do(argreplace(Term,I))).

argreplace(Term,I) :- 
arg(I,Term,Arg),string(Arg),string_to_var(Arg,Replace),setarg(I,Term,Replace),!. 
%argument is a string the replace
argreplace(Term,I) :- arg(I,Term,Arg),replaceBack(Arg).



Wit Jakuczun schrieb:
> W dniu 2010-06-24 16:28, Christian Wirth pisze:
>   
>> As Info:
>>
>> I fixed the problem by converting all variables to strings before
>> exporting (term_string)
>>    
>>     
> What do yo call variables? Are they Prolog variables?
> I would be grateful for some small example: what is this thing you are 
> trying to copy? :)
>
> Best regards
>
> PS
> By the way:   http://www.eclipse-clp.org/ - is not working...
>
>   
Received on Thu Jun 24 2010 - 15:45:12 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST