Re: [eclipse-clp-users] possible to turn strings into variable names?

From: WL Ko <u0605346_at_...229...>
Date: Thu, 11 Mar 2010 13:07:55 +0800
I get what you mean, I guess I probably should have made myself clearer: I 
would prefer to print out the original problem along with the solution, so 
that I can tell at once it is SEND + MORE, and not _519_521_523_525 + 
_527_529_531_521. In that case I would need something that can take in 
"[S,E,N,D]+[M,O,R,E]=[M,O,N,E,Y]", and print:
    SEND
+ MORE
MONEY



> WL Ko wrote:
>> Hi all,
>>
>> There exists a testing method that I've seen in some example programs, in
>> the form of having test(1, tree(a,nil,nil)) as a fact, and then running
>> test(1,X), in_order(X,L).
>>
>> I'm trying to apply that to a predicate that takes in variables with
>> particular names, like sendmore([S,E,N,D]+[M,O,R,E]=[M,O,N,E,Y]), and for
>> that to be possible with variables, it seems that I should store it as a
>> string, but I do not know of a way to convert the string back into a 
>> term...
>
> No, you don't need strings.
>
> Imagine that variables are really just "holes" or empty spaces
> in a data structure, which can be filled with actual values later.
>
> Variable _names_ are not used during computation, you only use them
> in a textual representation to indicate which of these empty spaces
> are the same, and which are different.
>
> For example, if you write [A,B,3,B,C] you are specifying a list with
> 5 elements, where the 3rd one is already known to be 3, and the others
> are still empty spaces.  However, by using the letter B for the 2nd and
> the 4th, you have indicated that both these positions really refer to
> the same empty space, and when this space gets filled, the value will
> appear in two places in the list.  So the names here are only used as a
> way to construct "a list where the 2nd and 4th elements are identical".
>
> You could have made a completely equivalent list (Xs) via any of the
> following pieces of code:
> ?- Xs = [_,Z,3,Z,_].
> ?- Xs = [A,B,C,D,E], B=D, C=3.
> ?- length(Xs,5), nth1(2,Xs,X), nth1(4,Xs,X), nth1(3,Xs,3).
> ?- functor(S,f,5), arg(2,S,X), arg(4,S,X), arg(3,S,3), S=..[_|Xs].
>
> To come back to your question: the sendmore/1 predicate only cares about
> the _structure_ of its input, i.e. where the variables are, and which of
> them are shared.  So nobody stops you from having facts like
> test(1, [S,E,N,D]+[M,O,R,E]=[M,O,N,E,Y]).
> and running your test by calling
> ?- test(1, Equation), sendmore(Equation), writeln(Equation).
>
> Easy, isn't it ;-)
>
> -- Joachim
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users 
Received on Thu Mar 11 2010 - 05:08:15 CET

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