map[K, V] — a language collection beside list and array.
phonebook.zg
# map[K, V] — a language collection beside list and array (decided 2026-09-22).# A missing key is a failure, not a check site: `otherwise` says what happens.MAIN{letmut'phones':map[str.utf8,int32]=map["ann"=5551,"bob"=5552];# a literal: key = valuemap.set[lend.mut'phones',key"ann",value5553];# same key: replacedstd::print.useful[map.length[lend'phones']," entries",newln];let'a':=map.get[lend'phones',key"ann"]otherwise0;let'c':=map.get[lend'phones',key"cat"]otherwise0;# missing → 0std::print.useful["ann ",'a',", cat ",'c',newln];ifmap.has[lend'phones',key"bob"]{std::print.useful["bob is in",newln];}let'gone':=map.remove[lend.mut'phones',key"bob"]otherwise0;# hands the value backstd::print.useful["removed ",'gone',", ",map.length[lend'phones']," left",newln];map.remove[lend.mut'phones',key"nobody"]otherwise{missing{std::print.useful["nobody to remove",newln];}};map.set[lend.mut'phones',key"cat",value5554];for'k'inmap.keys[lend'phones']{std::print.useful['k'," "];}# insertion order: ann catstd::print.stored[newln];for'e'inmap.pairs[lend'phones']{std::print.useful['e'.key,"=",'e'.value," "];}std::print.stored[newln];letmut'fast':map.unordered[str.utf8,int32]=map.empty;# chosen: never walkedmap.set[lend.mut'fast',key"x",value1];std::print.useful[map.has[lend'fast',key"x"],newln];let'who':=map.get[lend'phones',key"zed"]otherwise{missing{std::print.useful["no zed",newln];std::exit[0];}};}
Output
2 entries
ann 5553, cat 0
bob is in
removed 5552, 1 left
nobody to remove
ann cat
ann=5553 cat=5554
true
no zed