Re: Variable Names in Prolog
On Feb 21, 10:31*am, Jan Wielemaker <j...@invalid.invalid> wrote:
> On 2012-02-21, Feliks <feliks.kluzn...@utdallas.edu> wrote:
> > On Feb 20, 11:46*am, Nada Sharaf <nada.shara...@gmail.com> wrote:
> >> Hello all. I have a problem that since variable names are always
> >> replaced with ones that start with _G I cannot know the mapping back.
> >> So, is there a way to know that variable _G123 maps to X for example,
> >> so that I can print X or write it to a file instead of having _G123
> >> written.
> >> Thank you very much
> > This is probably a little more complicated than what you want, but...
> > In SWI-Prolog (is that what you are using?) you can do
> > * *read_term( Term, [ variable_names( VarDict ) ] )
> > You can then call your own printing procedure that uses the names from
> > VarDict whenever it prints variables. *I don't see a similar option in
> > write/2. :-(
> Bind the variables to e.g., '$VAR'('VarName') and call write_term using
> the option numbervars(true). *That is what the toplevel does.
> > The top level in SWI-Prolog will print your original variable names.
> > In general, many variables are created during the computation and just
> > don't have original names.
> My gut feelings tell me that the OP doesn't understand some quite basic
> Prolog principle, but I not sure which one ... E.g., are we talking
> about toplevel query variables or program text variables?
> * *Cheers --- Jan
> > Hope this helps a little,
> > -- Feliks
Thanks a lot for the reply.
I have one issue however,
I am using the CHR library so when the user enters leq(A,B) for
example, I take this and I write it to a file for further processing.
However what is written is leq(_G123,_G124) for example.
As far as I understand, I have to bind the variables first before I
try to write them from within the CHR program, so for example if the
rule is cons(N) ==> write_term(cons(N),[numbervars(true)])|true.
then the query the user inserts should for example be
toplevel_variables:bind_vars([M='$VAR'('M')]),cons(M), in order to be
able to know the original variable names and bind them. I mean that
the user should do the binding while inserting the query because
otherwise there is no way to tell that N is actually 'M'.
Is this correct?
Thank you very much for your help