I have been using the chr library along with the jpl interface. I have a general inquiry though. I send the constraints from SWI Prolog to an instance of a java class from within my CHR program. The thing is if the input constraint is leq(A,B) for example, the names of the variables are gone, and the variable names that appear start with _G. This happens even if I try to print leq(A,B) without using the interface at all. It appears that whenever the variable is processed the name is replaced with a fresh one. My question is whether there is a way to do the mapping back. For example whether there is a way to know that _G123 corresponds to A and so on. Thank you very much.
相关问题
- Creating a SPARQL parameterized query using append
- How to join rules and print out outputs in prolog
- Splitting list and iterating in prolog
- Accumulating while in recursion/backtracking
- prolog trace how to use
相关文章
- What are the problems associated to Best First Sea
- How can I fix this circular predicate in Prolog?
- How to negate in Prolog
- Remove incorrect subsequent solutions without once
- prolog two lists are exactly the same
- Simplify Expressions in Prolog
- Check if any element's frequency is above a li
- Prolog — symetrical predicates
(This question has nothing to do with CHR nor is it specific to SWI).
The variable names you use when writing a Prolog program are discarded completely by the Prolog system. The reason is that this information cannot be used to print variables accurately. There might be several independent instances of that variable. So one would need to add some unique identifier to the variable name. Also, maintaining that information at runtime would incur significant overheads.
To see this, consider a predicate
mylist/1
.Here, we have used the variable
_E
for each element of the list. The toplevel now prints all those elements with a unique identifier:The second answer might be printed as
Fs = [_E]
instead. But what about the third? It cannot be printed asFs = [_E,_E]
since the elements are different variables. So something likeFs = [_E_295,_E_298]
is the best we could get. However, this would imply a lot of extra book keeping.But there is also another reason, why associating source code variable names with runtime variables would lead to extreme complexities: In different places, that variable might have a different name. Here is an artificial example to illustrate this:
And the query:
What names, would you like, these two elements should have? The first element might have the name
_A
or_B
or maybe even better:_A_or_B
. Or, even_Ap1_and_Bp2
. For whom will this be a benefit?Note that the variable names mentioned in the query at the toplevel are retained:
So there is a way to get that information. On how to obtain the names of variables in SWI and YAP while reading a term, please refer to this question.