diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-01-12 16:49:58 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-01-12 16:49:58 -0500 |
| commit | 645d66e0de0f201404d9ad4b210f90c139a247ff (patch) | |
| tree | 08367c3631b928752cde94083bdfe2ae49db0b79 /docs | |
| parent | b025cf269d2e07e179be4a0e34d936862dc640c2 (diff) | |
Change table syntax to `{key=value}` and `{:K,V}`/`{K,V}`
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/arrays.md | 4 | ||||
| -rw-r--r-- | docs/functions.md | 2 | ||||
| -rw-r--r-- | docs/langs.md | 10 | ||||
| -rw-r--r-- | docs/libraries.md | 2 | ||||
| -rw-r--r-- | docs/tables.md | 58 | ||||
| -rw-r--r-- | docs/text.md | 16 |
6 files changed, 46 insertions, 46 deletions
diff --git a/docs/arrays.md b/docs/arrays.md index 7cae399a..29965fb4 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -325,7 +325,7 @@ Counts the occurrences of each element in the array. **Signature:** ```tomo -func counts(arr: [T] -> {T: Int}) +func counts(arr: [T] -> {T,Int}) ``` **Parameters:** @@ -338,7 +338,7 @@ A table mapping each element to its count. **Example:** ```tomo >> [10, 20, 30, 30, 30]:counts() -= {10: 1, 20: 1, 30: 3} += {10=1, 20=1, 30=3} ``` --- diff --git a/docs/functions.md b/docs/functions.md index 5ea2decd..edd1261a 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/langs.md b/docs/langs.md index 31ce275e..37141bdc 100644 --- a/docs/langs.md +++ b/docs/langs.md @@ -12,11 +12,11 @@ where a different type of string is needed. lang HTML: func escape(t:Text -> HTML): t = t:replace_all({ - $/&/: "&", - $/</: "<", - $/>/: ">", - $/"/: """, - $/'/: "'", + $/&/ = "&", + $/</ = "<", + $/>/ = ">", + $/"/ = """, + $/'/ = "'", }) return HTML.without_escaping(t) diff --git a/docs/libraries.md b/docs/libraries.md index 5aea0811..983497fa 100644 --- a/docs/libraries.md +++ b/docs/libraries.md @@ -51,7 +51,7 @@ Now, what happens if we want to _use_ the compiled object file? foo := use ./foo.tm func say_stuff(): - say("I got {foo.my_variable} from foo") + say("I got $(foo.my_variable) from foo") func main(): say_stuff() diff --git a/docs/tables.md b/docs/tables.md index a8a2793f..5af26396 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -17,20 +17,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 arrays, 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 : Int? >> 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 : Int? ``` @@ -75,9 +75,9 @@ table value: ```tomo >> t2.fallback -= {"A":10} : {Text:Int}? += {"A"=10} : {Text,Int}? >> t.fallback -= none : {Text:Int}? += none : {Text,Int}? ``` ## Setting Values @@ -86,11 +86,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 @@ -98,7 +98,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 ``` @@ -108,7 +108,7 @@ The keys and values of a table can be efficiently accessed as arrays 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 @@ -141,7 +141,7 @@ not already in the table, its value will be assumed to be zero. **Signature:** ```tomo -func bump(t:@{K:V}, key: K, amount: Int = 1 -> Void) +func bump(t:@{K,V}, key: K, amount: Int = 1 -> Void) ``` **Parameters:** @@ -155,11 +155,11 @@ Nothing. **Example:** ```tomo ->> t := {"A":1} +>> t := {"A"=1} t:bump("A") t:bump("B", 10) >> t -= {"A": 2, "B": 10} += {"A"=2, "B"=10} ``` --- @@ -171,7 +171,7 @@ Removes all key-value pairs from the table. **Signature:** ```tomo -func clear(t:@{K:V}) +func clear(t:@{K,V}) ``` **Parameters:** @@ -195,7 +195,7 @@ Retrieves the value associated with a key, or returns null if the key is not pre **Signature:** ```tomo -func get(t:{K:V}, key: K -> V?) +func get(t:{K,V}, key: K -> V?) ``` **Parameters:** @@ -208,7 +208,7 @@ The value associated with the key or null if the key is not found. **Example:** ```tomo ->> t := {"A":1, "B":2} +>> t := {"A"=1, "B"=2} >> t:get("A") = 1 : Int? @@ -231,7 +231,7 @@ Checks if the table contains a specified key. **Signature:** ```tomo -func has(t:{K:V}, key: K -> Bool) +func has(t:{K,V}, key: K -> Bool) ``` **Parameters:** @@ -244,9 +244,9 @@ func has(t:{K:V}, key: K -> Bool) **Example:** ```tomo ->> {"A":1, "B":2}:has("A") +>> {"A"=1, "B"=2}:has("A") = yes ->> {"A":1, "B":2}:has("xxx") +>> {"A"=1, "B"=2}:has("xxx") = no ``` @@ -259,7 +259,7 @@ Removes the key-value pair associated with a specified key. **Signature:** ```tomo -func remove(t:{K:V}, key: K -> Void) +func remove(t:{K,V}, key: K -> Void) ``` **Parameters:** @@ -272,10 +272,10 @@ Nothing. **Example:** ```tomo -t := {"A":1, "B":2} +t := {"A"=1, "B"=2} t:remove("A") >> t -= {"B": 2} += {"B"=2} ``` --- @@ -287,7 +287,7 @@ Sets or updates the value associated with a specified key. **Signature:** ```tomo -func set(t:{K:V}, key: K, value: V -> Void) +func set(t:{K,V}, key: K, value: V -> Void) ``` **Parameters:** @@ -301,8 +301,8 @@ Nothing. **Example:** ```tomo -t := {"A": 1, "B": 2} +t := {"A"=1, "B"=2} t:set("C", 3) >> t -= {"A": 1, "B": 2, "C": 3} += {"A"=1, "B"=2, "C"=3} ``` diff --git a/docs/text.md b/docs/text.md index fd37d4df..0384aa41 100644 --- a/docs/text.md +++ b/docs/text.md @@ -279,7 +279,7 @@ Text.find_all(pattern:Pattern -> [Match]) Text.matches(pattern:Pattern -> [Text]?) Text.map(pattern:Pattern, fn:func(m:Match -> Text) -> Text) Text.replace(pattern:Pattern, replacement:Text, placeholder:Pattern=$// -> [Text]) -Text.replace_all(replacements:{Pattern:Text}, placeholder:Pattern=$// -> [Text]) +Text.replace_all(replacements:{Pattern,Text}, placeholder:Pattern=$// -> [Text]) Text.split(pattern:Pattern -> [Text]) Text.trim(pattern=$/{whitespace}/, trim_left=yes, trim_right=yes -> [Text]) ``` @@ -1183,7 +1183,7 @@ See [`replace()`](#replace) for more information about replacement behavior. **Signature:** ```tomo -func replace_all(replacements:{Pattern:Text}, backref: Pattern = $/\/ -> Text) +func replace_all(replacements:{Pattern,Text}, backref: Pattern = $/\/ -> Text) ``` **Parameters:** @@ -1206,15 +1206,15 @@ replacement text. **Example:** ```tomo >> "A <tag> & an amperand":replace_all({ - $/&/: "&", - $/</: "<", - $/>/: ">", - $/"/: """, - $/'/: "'", + $/&/ = "&", + $/</ = "<", + $/>/ = ">", + $/"/ = """, + $/'/ = "'", } = "A <tag> & an ampersand" ->> "Hello":replace_all({$/{lower}/:"[\0]", $/{upper}/:"{\0}"}) +>> "Hello":replace_all({$/{lower}/="[\0]", $/{upper}/="{\0}"}) = "{H}[ello]" ``` |
