Updated and added examples
Getty Ritter
8 years ago
1 | 1 |
{
|
2 | 2 |
|
3 | 3 |
# 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
|
6 | 6 |
|
7 | |
"one": 1 # integers
|
| 7 |
"one": 1, # integers
|
8 | 8 |
|
9 | |
"two": 2.0 # floats
|
| 9 |
"two": 2.0, # floats
|
10 | 10 |
|
11 | 11 |
"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 |
],
|
16 | 16 |
|
17 | 17 |
"four": # stitched expressions are fully contained in parens
|
18 | |
( 2 + 2 )
|
| 18 |
( 2 + 2 ),
|
19 | 19 |
|
20 | 20 |
# the with keyword introduces a binding, of the form
|
21 | |
# with ( [ident] [arg1 arg2 ... argn] = [expr] )
|
| 21 |
# with [ident] [arg1 arg2 ... argn] = [expr];
|
22 | 22 |
# 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;
|
26 | 25 |
|
27 | |
"five": (incr 4)
|
| 26 |
"five": (incr 4),
|
28 | 27 |
|
29 | 28 |
# this entire file denotes the JSON document
|
30 | 29 |
# { "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 |
]⏎
|
1 | 1 |
{
|
2 | 2 |
|
3 | 3 |
# 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
|
6 | 5 |
|
7 | |
"one": 1 # integers
|
| 6 |
"one": 1, # integers
|
8 | 7 |
|
9 | |
"two": 2.0 # floats
|
| 8 |
"two": 2.0, # floats
|
10 | 9 |
|
11 | 10 |
# lists use square brackets
|
12 | 11 |
"three":
|
13 | 12 |
[
|
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 |
],
|
18 | 17 |
|
19 | 18 |
}
|
| 1 |
[ # stitching of expressions
|
| 2 |
]⏎
|