gdritter repos virgil / 189abc8
Updated and added examples Getty Ritter 7 years ago
4 changed file(s) with 55 addition(s) and 22 deletion(s). Collapse all Expand all
11 {
22
33 # comments start with an octothorpe
4 # objects are created with key-value pairs, but don't use
5 # commas or colons
4 # objects are created with key-value pairs separated
5 # by commas
66
7 "one": 1 # integers
7 "one": 1, # integers
88
9 "two": 2.0 # floats
9 "two": 2.0, # floats
1010
1111 "three": [ # lists use square brackets
12 "s" # the string syntax is identical to JSON's
13 "s" # again, no commas are necessary
14 "0"
15 ]
12 "s", # the string syntax is identical to JSON's
13 "s",
14 "0", # trailing commas ARE allowed
15 ],
1616
1717 "four": # stitched expressions are fully contained in parens
18 ( 2 + 2 )
18 ( 2 + 2 ),
1919
2020 # the with keyword introduces a binding, of the form
21 # with ( [ident] [arg1 arg2 ... argn] = [expr] )
21 # with [ident] [arg1 arg2 ... argn] = [expr];
2222 # these can occur anywhere and are ignored, but are scoped
23 # to the data structure in which they occur
24 with
25 incr x = x + 1;
23 # to the data structure in which they occur (?)
24 with incr x = x + 1;
2625
27 "five": (incr 4)
26 "five": (incr 4),
2827
2928 # this entire file denotes the JSON document
3029 # { "one": 1,
1 [
2 # Virgil allows list and dictionary comprehensions in
3 # code splices
4
5 `[ x | x in [ 1, 2, 3 ] ],
6
7 # comprehensions over multiple generators
8 `[ [x,y] | x in [ 1, 2 ]
9 , y in [ 1, 2 ]
10 ],
11
12 # parallel comprehensions
13 `[ [x,y] | x in [ 1, 2 ]
14 | y in [ 1, 2 ]
15 ],
16
17 `{ v: k | k: v in { "one": "un", "two": "du", "three": "tri" } },
18
19 # the generator expression can be either a list or a dict,
20 # regardless of the final value of the comprehension
21
22 `{ str(x): x + 1 | x in [ 1, 2, 3 ] },
23
24 # this file is equivalent to
25 # [
26 # [ 1, 2, 3 ],
27 # [ [1,1], [1,2], [2,1], [2,2] ],
28 # [ [1,1], [2,2], ],
29 # { "un": "one", "du": "two", "tri": "three" },
30 # { "1": 1, "two": 2, "three": 3 },
31 # ]
32
33 ]
11 {
22
33 # comments start with an octothorpe
4 # objects are created with key-value pairs, but don't use
5 # commas or colons
4 # objects are created with key-value pairs
65
7 "one": 1 # integers
6 "one": 1, # integers
87
9 "two": 2.0 # floats
8 "two": 2.0, # floats
109
1110 # lists use square brackets
1211 "three":
1312 [
14 "s" # the string syntax is identical to JSON's
15 "s" # again, no commas are necessary
16 "0"
17 ]
13 "s", # the string syntax is identical to JSON's
14 "s",
15 "0", # trailing commas are allowed
16 ],
1817
1918 }
1 [ # stitching of expressions
2 ]