users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use the Global variables on the GNU Prolog ?


From: Daniel Diaz
Subject: Re: How to use the Global variables on the GNU Prolog ?
Date: Mon, 21 Feb 2005 11:24:18 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a5) Gecko/20041122

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]