For Programmers: Free Programming Magazines  


Home > Archive > Prolog > November 2005 > Convert a "global variable"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Convert a "global variable"
Thomas Wölfl

2005-11-19, 6:58 pm

Hi All,

I use assert / retract to set a value which should be accessible in the same
way as a global variable in a functional language. I know that this is not a
good programming style in PROLOG. As long as my program contains assert /
retract I can not use automatic theorem provers (like LPTP:
http://www.inf.ethz.ch/personal/staerk/lptp.html ) in order to prove
left-termination. Robert Staerk writes on this page:

"Non-logical predicates and control operators like cut (!), assert/1,
retract/1, var/1 are forbidden, since they destroy either the lifting
property or modify the program during run-time."

Is there any standard way to convert a global variable to a local one?

I could pass the "global" variable as argument between all predicates of my
program. For example let Path be such a variable. I call the predicate
-? test(x, px, Path).
and it fails. Now, Path should contain the path of the derivation, i.e. the
reason why test failed. However, since test failed, Path is unbound, e.g.
Path = _L123.

Thanks for your help,
Thomas


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com