gdritter repos virgil / master examples / Comp.vgl
master

Tree @master (Download .tar.gz)

Comp.vgl @masterraw · history · blame

[
  # Virgil allows list and dictionary comprehensions in
  # code splices
  
  `[ x | x in [ 1, 2, 3 ] ],

  # comprehensions over multiple generators
  `[ [x,y] | x in [ 1, 2 ]
           , y in [ 1, 2 ]
   ],

  # parallel comprehensions
  `[ [x,y] | x in [ 1, 2 ]
           | y in [ 1, 2 ]
   ],
  
  `{ v: k | k: v in { "one": "un", "two": "du", "three": "tri" } },
  
  # the generator expression can be either a list or a dict,
  # regardless of the final value of the comprehension

  `{ str(x): x + 1 | x in [ 1, 2, 3 ] },

  # this file is equivalent to
  # [
  #   [ 1, 2, 3 ],
  #   [ [1,1], [1,2], [2,1], [2,2] ],
  #   [ [1,1], [2,2], ],
  #   { "un": "one", "du": "two", "tri": "three" },
  #   { "1": 1, "two": 2, "three": 3 },
  # ]

]