Re: How to use the Global variables on the GNU Prolog ?
Daniel Diaz <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
You can also use the GNU Prolog specific global variables, see for instance (several examples are given): http://gprolog.inria.fr/manual/manual044.html The Vic's example can then also be formulated using: g_assign(Name, 0) to init the value to 0. g_read(Name, Number) to get the current value of Name g_inc(Name, Number) increments Name and unifies Number with the new value Vic Bancroft wrote: > Simple User wrote: > >> How to use the Global variables on the GNU Prolog? >> >> > If you intend to have a prolog database, then the most natural fit might > be to assert literals. Just use a dynamic/1 directive and simply assert > and retract them. > > :- dynamic( atom_counter/2 ). > > /** counters( +Name, -Number ) > * > * Given an atom, records an incrementing number, begining with zero. > * > */ > counters( Name, Number ) :- > atom_counter( Name, LastNumber ), > retract( atom_counter( Name, LastNumber ) ), > Number is LastNumber + 1, > assertz( atom_counter( Name, Number ) ), > !. > > counters( Name, 0 ) :- > assertz( atom_counter( Name, 0 ) ), > !. > >> I want a sample. >> >> > For more context you are welcome to read, > > http://elvis.dlogic.org/~bancroft/pub/gplfaq/faq_parse.pl >