map_vars.ion 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. echo '# ANCHOR: testing_maps'
  2. let map:hmap[str] = [key1=one key3=three]
  3. let map[key2] = two
  4. echo @map[key1]
  5. echo @map[key2]
  6. echo @map[key3]
  7. let map:hmap[int] = [uno=1 dos=2 tres=3]
  8. echo @map[uno]
  9. echo @map[tres]
  10. echo @map[dos]
  11. let map:hmap[[int]] = [key1=[1 2 3 4 5] key2=[6 7 8]]
  12. echo @map[key1]
  13. echo @map[key2]
  14. let map:bmap[str] = [key1=one key3=three]
  15. echo @map
  16. let map[key2] = two
  17. echo @map
  18. echo @map[key1]
  19. echo @map[key2]
  20. echo @map[key3]
  21. let map:bmap[float] = [ichi=1.0 ni=2.0 san=3.0]
  22. echo @map
  23. let map[ichi] = foo
  24. echo @map
  25. let map[ni] = bar
  26. echo @map
  27. echo '# ANCHOR_END: testing_maps'
  28. echo '# ANCHOR: hashmap'
  29. let hashmap:hmap[str] = [ blue=pc27 red=pc2 green=pc15 ]
  30. let x = blue
  31. echo @hashmap[$x] @hashmap[red] # fetch values
  32. let hashmap[orange] = pc22 # add new key with value
  33. #echo @keys(hashmap) #get keys
  34. #echo @values(hashmap) #get values
  35. #echo @hashmap #get keys and values
  36. #for key value in @hashmap #use keys and values
  37. # echo $key: $value
  38. #end
  39. echo '# ANCHOR_END: hashmap'
  40. echo '# ANCHOR: btreemap'
  41. let btreemap:bmap[str] = [ pc2=red pc15=green pc27=blue ]
  42. let x = pc2
  43. echo @btreemap[$x] @btreemap[pc15] # fetch values
  44. let btreemap[orange] = pc22 # add new key with value
  45. echo @keys(btreemap) #get keys
  46. echo @values(btreemap) #get values
  47. echo @btreemap #get keys and values
  48. for key value in @btreemap #use keys and values
  49. echo $key: $value
  50. end
  51. echo '# ANCHOR_END: btreemap'