/* Associative array/Creation in Picat. From Rosetta Code http://rosettacode.org/wiki/Associative_array/Creation """ In this task, the goal is to create an associative array (also known as a dictionary, map, or hash). """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => Map = new_map(), println(Map), % add some data Map.put(a,1), Map.put("picat",2), Map.put("picat",3), % overwrite values Map.put([a,list,of,different,"things",[including, lists],3.14159],2), println(Map), println(a=Map.get(a)), % println(a=Map.a), % sometimes we don't have to use get/1 explicitly println(b=Map.get(b,'default value')), % the second argument to get/2 is the default value % create a map from a list of values Map2 = new_map([K=V : {K,V} in zip([a,b,c,d,e,f,g,h],1..8)]), println(Map2), println(h=Map2.get(h)), if not Map2.has_key(z) then println("don't have key 'z'") end, println(keys=Map2.keys()), println(values=Map2.values()), println([K : K=V in Map2, V mod 2=0]), % not sorted nl.