Picat does not support global variables as in traditional imperative languages. There are (at least) three ways for doing something similar:
* add the variables in the calls to the functions/predicates, for example using a single "master map" that contains all maps
* add the data as facts in the global database (cf my beats/2 as you mentioned ).
A simple example (not relevant to today's problem) is to set a single value as global accessible :
number_of_players(4).
Here is a more relevant example:
map_other("A","Rock").
map_other("B","Paper").
map_other("C","Scissors").
map_me1("X","Rock").
map_me1("Y","Paper").
map_me1("Z","Scissors").
map_me2("X","Loose").
map_me2("Y","Draw").
map_me2("Z","Win").
map_points("Rock",1).
map_points("Paper",2).
map_points("Scissors",3).
This is a nice (Prolog) approach, especially if one want to access the facts in both directions .e.g
map_me2(A,"Loose") -> A="X"
map_me2("Z",B) -> B ="Win"
To simplify this, one can add these facts "programmatically" to the database using cl_facts/1:
cl_facts($[map_other("A","Rock"),map_other("B","Paper"),map_other("C","Scissors"),
map_me1("X","Rock"), map_me1("Y","Paper"), map_me1("Z","Scissors"),
map_me2("X","Loose"), map_me2("Y","Draw"), map_me2("Z","Win"),
map_points("Rock",1), map_points("Paper",2), map_points("Scissors",3)
]),
Note that cl_facts/1 only works for simple facts, not predicates or functions. Also see cl_facts/2 and cl_facts_table/1-2.
* use get_global_map(). Here's a simple example:
"""
main =>
Map = get_global_map(),
Map.put(a,1),Map.put(b,2),Map.put(c,3),
test().
test =>
Map = get_global_map(),
println(Map.get(a).
"""
The drawback of this approach is that one has to access the global map using get_global_map/0 in each predicate.
There are variants of global maps which have some different behaviours regarding backtracking etc: see get_table_map/0 and get_heap_map/0.
A small style comment in your code: I note that you tend to use ":=" for simple assignments (unification in Prolog parlance). It's better style to use "=" for these unifications and only use ":=" when/if you are re-assigning a variable.