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

From: Christian Wirth <tyrion_at_geek-squad.de>
Date: Thu, 24 Jun 2010 18:07:57 +0200
An example:

TermA=[1,test("_11","_12") :- 
+(1,"_11","_12")],TermB=[2,test("_11","_13") :- 
+(2,"_11","_13")],List=[TermA,TermB],constToVarRecList(List),List=[[1,test(1,A) 
:- _]|_]
All occurances of _11 should be 1 and _12=A after this, but it isn't

the unconverted version would be:
TermA=[1,test(_11,_12) :- +(1,_11,_12)],TermB=[2,test(_11,_13) :- 
+(2,_11,_13)],List=[TermA,TermB],List=[[1,test(1,A) :- _]|_]
 and this works ofc.

best regards

Christian Wirth schrieb:
> 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...
>>
>>   
>>     
>
>
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate 
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
> lucky parental unit.  See the prize list and enter to win: 
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
>   
Received on Thu Jun 24 2010 - 16:08:06 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET