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 /test/tables.tm | |
| parent | b025cf269d2e07e179be4a0e34d936862dc640c2 (diff) | |
Change table syntax to `{key=value}` and `{:K,V}`/`{K,V}`
Diffstat (limited to 'test/tables.tm')
| -rw-r--r-- | test/tables.tm | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/test/tables.tm b/test/tables.tm index 6abbbe36..c97c35a0 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -1,6 +1,6 @@ func main(): - >> t := {"one":1, "two":2} - = {"one":1, "two":2} + >> t := {"one"=1, "two"=2} + = {"one"=1, "two"=2} >> t["one"] = 1 : Int? @@ -15,22 +15,22 @@ func main(): t_str := "" for k,v in t: - t_str ++= "($k:$v)" + t_str ++= "($k=$v)" >> t_str - = "(one:1)(two:2)" + = "(one=1)(two=2)" >> t.length = 2 >> t.fallback - = none : {Text:Int}? + = none : {Text,Int}? >> t.keys = ["one", "two"] >> t.values = [1, 2] - >> t2 := {"three":3; fallback=t} - = {"three":3; fallback={"one":1, "two":2}} + >> t2 := {"three"=3; fallback=t} + = {"three"=3; fallback={"one"=1, "two"=2}} >> t2["one"] = 1 : Int? @@ -42,28 +42,28 @@ func main(): >> t2.length = 1 >> t2.fallback - = {"one":1, "two":2} : {Text:Int}? + = {"one"=1, "two"=2} : {Text,Int}? t2_str := "" for k,v in t2: - t2_str ++= "($k:$v)" + t2_str ++= "($k=$v)" >> t2_str - = "(three:3)" + = "(three=3)" - >> {i:10*i for i in 5} - = {1:10, 2:20, 3:30, 4:40, 5:50} - >> {i:10*i for i in 5 if i mod 2 != 0} - = {1:10, 3:30, 5:50} - >> {x:10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5} - = {2:20, 3:30, 4:40} + >> {i=10*i for i in 5} + = {1=10, 2=20, 3=30, 4=40, 5=50} + >> {i=10*i for i in 5 if i mod 2 != 0} + = {1=10, 3=30, 5=50} + >> {x=10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5} + = {2=20, 3=30, 4=40} - >> t3 := @{1:10, 2:20, 3:30} + >> t3 := @{1=10, 2=20, 3=30} >> t3:remove(3) >> t3 - = @{1:10, 2:20} + = @{1=10, 2=20} do: - >> plain := {1:10, 2:20, 3:30} + >> plain := {1=10, 2=20, 3=30} >> plain[2]! = 20 >> plain[2]! @@ -75,29 +75,29 @@ func main(): >> plain:has(456) = no - >> fallback := {4:40; fallback=plain} + >> fallback := {4=40; fallback=plain} >> fallback:has(1) = yes >> fallback[1] or -999 = 10 do: - >> t4 := &{"one": 1} + >> t4 := &{"one"= 1} >> t4["one"] = 999 >> t4["two"] = 222 >> t4 - = &{"one":999, "two":222} + = &{"one"=999, "two"=222} do: - >> {1:1, 2:2} == {2:2, 1:1} + >> {1=1, 2=2} == {2=2, 1=1} = yes - >> {1:1, 2:2} == {1:1, 2:999} + >> {1=1, 2=2} == {1=1, 2=999} = no - >> {1:1, 2:2} <> {2:2, 1:1} + >> {1=1, 2=2} <> {2=2, 1=1} = 0 - >> [{:Int:Int}, {0:0}, {99:99}, {1:1, 2:2, 3:3}, {1:1, 99:99, 3:3}, {1:1, 2:-99, 3:3}, {1:1, 99:-99, 3:4}]:sorted() - = [{}, {0:0}, {1:1, 2:-99, 3:3}, {1:1, 2:2, 3:3}, {1:1, 99:99, 3:3}, {1:1, 99:-99, 3:4}, {99:99}] + >> [{:Int,Int}, {0=0}, {99=99}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 2=-99, 3=3}, {1=1, 99=-99, 3=4}]:sorted() + = [{}, {0=0}, {1=1, 2=-99, 3=3}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 99=-99, 3=4}, {99=99}] >> [{:Int}, {1}, {2}, {99}, {0, 3}, {1, 2}, {99}]:sorted() = [{}, {0, 3}, {1}, {1, 2}, {2}, {99}, {99}] |
