diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 18:01:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 18:01:19 -0400 |
| commit | 68bedd3c23757a8576e77f38e38ddcf9ecd26d19 (patch) | |
| tree | 86ce1610143efc43453f50d3413925797601c48a /docs | |
| parent | 0815de981c683cac7dbac082ee14c11894089f31 (diff) | |
Use colons instead of '=' for tables (e.g. {1: 2})
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/functions.md | 2 | ||||
| -rw-r--r-- | docs/tables.md | 32 |
2 files changed, 17 insertions, 17 deletions
diff --git a/docs/functions.md b/docs/functions.md index d68d72d0..72279c11 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -82,7 +82,7 @@ func _add(x, y:Int -> Int) return x + y struct add_args(x,y:Int) -add_cache : @{add_args=Int} = @{} +add_cache : @{add_args: Int} = @{} func add(x, y:Int -> Int) args := add_args(x, y) diff --git a/docs/tables.md b/docs/tables.md index 2f07436a..eaf0083e 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -7,30 +7,30 @@ support *all* types as both keys and values. ## Syntax -Tables are written using `{}` curly braces with `=` equals signs associating key +Tables are written using `{}` curly braces with `:` colons associating key expressions with value expressions and commas between entries: ```tomo -table := {"A"=10, "B"=20} +table := {"A": 10, "B": 20} ``` Empty tables must specify the key and value types explicitly: ```tomo -empty : {Text=Int} = {} +empty : {Text:Int} = {} ``` For type annotations, a table that maps keys with type `K` to values of type -`V` is written as `{K=V}`. +`V` is written as `{K:V}`. ### Comprehensions Similar to lists, tables can use comprehensions to dynamically construct tables: ```tomo -t := {i=10*i for i in 10} -t := {i=10*i for i in 10 if i mod 2 == 0} -t := {-1=-10, i=10*i for i in 10} +t := {i: 10*i for i in 10} +t := {i: 10*i for i in 10 if i mod 2 == 0} +t := {-1: -10, i: 10*i for i in 10} ``` ## Accessing Values @@ -39,7 +39,7 @@ Table values can be accessed with square bracket indexing. The result is an optional value: ```tomo -table := {"A"=1, "B"=2} +table := {"A": 1, "B": 2} >> table["A"] = 1? >> table["missing"] @@ -64,8 +64,8 @@ Tables can specify a fallback table that is used when looking up a value if it is not found in the table itself: ```tomo -t := {"A"=10} -t2 := {"B"=20; fallback=t} +t := {"A": 10} +t2 := {"B": 20; fallback=t} >> t2["A"] = 10? ``` @@ -75,7 +75,7 @@ table value: ```tomo >> t2.fallback -= {"A"=10}? += {"A": 10}? >> t.fallback = none ``` @@ -86,7 +86,7 @@ Tables can specify a default value which will be returned if a value is not present in the table or its fallback (if any). ```tomo -counts := &{"foo"=12; default=0} +counts := &{"foo": 12; default=0} >> counts["foo"] = 12 >> counts["baz"] @@ -105,11 +105,11 @@ You can assign a new key/value mapping or overwrite an existing one using `.set(key, value)` or an `=` assignment statement: ```tomo -t := {"A"=1, "B"=2} +t := {"A": 1, "B": 2} t["B"] = 222 t["C"] = 333 >> t -= {"A"=1, "B"=222, "C"=333} += {"A": 1, "B": 222, "C": 333} ``` ## Length @@ -117,7 +117,7 @@ t["C"] = 333 Table length can be accessed by the `.length` field: ```tomo ->> {"A"=10, "B"=20}.length +>> {"A": 10, "B": 20}.length = 2 ``` @@ -127,7 +127,7 @@ The keys and values of a table can be efficiently accessed as lists using a constant-time immutable slice of the internal data from the table: ```tomo -t := {"A"=10, "B"=20} +t := {"A": 10, "B": 20} >> t.keys = ["A", "B"] >> t.values |
