SHARE
TWEET

creatures.v

a guest Aug 18th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2.  
  3. struct Section {
  4.         description string
  5.         values map[string]string
  6. }
  7.  
  8. fn (s Section) str() string {
  9.         return 'description: "$s.description" \nvalues: ' + s.values.str()
  10. }
  11. fn (sectionMap map[string]Section) str() string {
  12.         mut res := []string
  13.         res << 'map of sections:'
  14.         for k,v in sectionMap {
  15.                 res << 'k: $k | v: ' + v.str()
  16.         }
  17.         return res.join('\n')
  18. }
  19.  
  20. fn main(){
  21.         mut all := map[string]Section
  22.         all['people'] = Section{ description: 'These are people' }
  23.         all['people'].values['John'] = 'Smith'
  24.         all['people'].values['Diana'] = 'Blanca'
  25.         all['animals'] = Section{ description: 'These are animals' }
  26.         all['animals'].values['cat'] = 'Tom'
  27.         all['animals'].values['mouse'] = 'Jerry'
  28.         println('The mouse is named: ' + all['animals'].values['mouse'] )
  29.  
  30.         println('All creatures:')
  31.         println(all)
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top