From 3c0a8f0b899a343f43caf9c95147b2cf77a7b525 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 28 Apr 2024 14:58:55 -0400 Subject: Syntax tweak: use ':' for blocks --- test/arrays.tm | 30 +++++++++++++++--------------- test/corecursive_func.tm | 14 +++++++------- test/enums.tm | 6 +++--- test/extern.tm | 2 +- test/for.tm | 26 +++++++++++++------------- test/functions.tm | 6 +++--- test/integers.tm | 4 ++-- test/lambdas.tm | 8 ++++---- test/lang.tm | 10 +++++----- test/minmax.tm | 6 +++--- test/nums.tm | 2 +- test/reductions.tm | 2 +- test/structs.tm | 8 ++++---- test/tables.tm | 6 +++--- test/text.tm | 2 +- test/use.tm | 4 ++-- test/use_import.tm | 4 ++-- 17 files changed, 70 insertions(+), 70 deletions(-) (limited to 'test') diff --git a/test/arrays.tm b/test/arrays.tm index be767fab..de1771b7 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -1,9 +1,9 @@ -func main() - if yes +func main(): + if yes: >> [:Num32] = [] : [Num32] - if yes + if yes: >> arr := [10, 20, 30] = [10, 20, 30] @@ -16,18 +16,18 @@ func main() = 3 sum := 0 - for x in arr + for x in arr: sum += x >> sum = 60 str := "" - for i,x in arr + for i,x in arr: str ++= "({i},{x})" >> str = "(1,10)(2,20)(3,30)" - if yes + if yes: >> arr := [10, 20] ++ [30, 40] = [10, 20, 30, 40] @@ -39,7 +39,7 @@ func main() >> arr = [10, 20, 30, 40, 50, 60, 70] - if yes + if yes: >> arr := [10, 20] >> copy := arr >> arr ++= 30 @@ -48,7 +48,7 @@ func main() >> copy = [10, 20] - if yes + if yes: >> [10*i for i in 5] = [10, 20, 30, 40, 50] @@ -61,7 +61,7 @@ func main() >> [x for x in y if x > 1 for y in [3, 4, 5] if y < 5] = [2, 3, 2, 3, 4] - if yes + if yes: >> arr := @[10, 20] >> copy := arr[] >> arr:insert(30) @@ -70,12 +70,12 @@ func main() >> copy = [10, 20] - if yes + if yes: >> arr := [10, 20, 30] >> arr:reversed() = [30, 20, 10] - if yes + if yes: >> nums := [10, -20, 30] // Sorted function doesn't mutate original: >> nums:sorted() @@ -96,20 +96,20 @@ func main() >> ["A", "B", "C"]:sample(10, [1.0, 0.5, 0.0]) - if yes + if yes: >> heap := [Int.random(max=50) for _ in 10] >> heap:heapify() >> heap sorted := [:Int] - while #heap > 0 + while #heap > 0: sorted:insert(heap:heap_pop()) >> sorted == sorted:sorted() = yes - for _ in 10 + for _ in 10: heap:heap_push(Int.random(max=50)) >> heap sorted = [:Int] - while #heap > 0 + while #heap > 0: sorted:insert(heap:heap_pop()) >> sorted == sorted:sorted() = yes diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm index 22ffd627..a5c13dde 100644 --- a/test/corecursive_func.tm +++ b/test/corecursive_func.tm @@ -1,15 +1,15 @@ -func ping(x:Int)->[Text] - if x > 0 +func ping(x:Int)->[Text]: + if x > 0: return ["ping: {x}"] ++ pong(x-1) - else + else: return ["ping: {x}"] -func pong(x:Int)->[Text] - if x > 0 +func pong(x:Int)->[Text]: + if x > 0: return ["pong: {x}"] ++ ping(x-1) - else + else: return ["pong: {x}"] -func main() +func main(): >> ping(3) = ["ping: 3", "pong: 2", "ping: 1", "pong: 0"] diff --git a/test/enums.tm b/test/enums.tm index c06862a3..1bc26203 100644 --- a/test/enums.tm +++ b/test/enums.tm @@ -1,6 +1,6 @@ enum Foo(Zero, One(x:Int), Two(x,y:Int)) -func main() +func main(): >> Foo.Zero = Foo.Zero >> Foo.One(123) @@ -27,9 +27,9 @@ func main() >> t[Foo.Zero] = "missing" - when x is o:One + when x is o:One: >> o.x = 123 - else + else: fail("Oops") diff --git a/test/extern.tm b/test/extern.tm index 896c5730..da3b1820 100644 --- a/test/extern.tm +++ b/test/extern.tm @@ -1,5 +1,5 @@ extern CORD_cat:func(a:Text, b:Text)->Text -func main() +func main(): >> CORD_cat("hello ", "world") = "hello world" diff --git a/test/for.tm b/test/for.tm index 63656380..a050c892 100644 --- a/test/for.tm +++ b/test/for.tm @@ -1,35 +1,35 @@ -func all_nums(nums:[Int])->Text +func all_nums(nums:[Int])->Text: result := "" - for num in nums + for num in nums: result ++= "{num}," - else + else: return "EMPTY" return result -func labeled_nums(nums:[Int])->Text +func labeled_nums(nums:[Int])->Text: result := "" - for i,num in nums + for i,num in nums: result ++= "{i}:{num}," - else + else: return "EMPTY" return result -func table_str(t:{Text:Text})->Text +func table_str(t:{Text:Text})->Text: str := "" - for k,v in t + for k,v in t: str ++= "{k}:{v}," - else return "EMPTY" + else: return "EMPTY" return str -func table_key_str(t:{Text:Text})->Text +func table_key_str(t:{Text:Text})->Text: str := "" - for k in t + for k in t: str ++= "{k}," - else return "EMPTY" + else: return "EMPTY" return str -func main() +func main(): >> all_nums([10,20,30]) = "10,20,30," >> all_nums([:Int]) diff --git a/test/functions.tm b/test/functions.tm index 13cdee55..426c33b1 100644 --- a/test/functions.tm +++ b/test/functions.tm @@ -1,10 +1,10 @@ -func add(x:Int, y:Int)->Int +func add(x:Int, y:Int)->Int: return x + y -func cached_heap(x:Int; cached)->@Int +func cached_heap(x:Int; cached)->@Int: return @x -func main() +func main(): >> add(3, 5) = 8 diff --git a/test/integers.tm b/test/integers.tm index 9b573aac..94ab8ac6 100644 --- a/test/integers.tm +++ b/test/integers.tm @@ -1,4 +1,4 @@ -func main() +func main(): >> 2 + 3 = 5 @@ -27,7 +27,7 @@ func main() = 1 nums := "" - for x in 5 + for x in 5: nums ++= "{x}," >> nums = "1,2,3,4,5," diff --git a/test/lambdas.tm b/test/lambdas.tm index a445540b..0ec0826b 100644 --- a/test/lambdas.tm +++ b/test/lambdas.tm @@ -1,13 +1,13 @@ -func make_adder(x:Int)-> func(y:Int)->Int +func make_adder(x:Int)-> func(y:Int)->Int: return func(y:Int) x + y -func suffix_fn(fn:func(t:Text)->Text, suffix:Text)->func(t:Text)->Text +func suffix_fn(fn:func(t:Text)->Text, suffix:Text)->func(t:Text)->Text: return func(t:Text) fn(t)++suffix -func mul_func(n:Int, fn:func(x:Int)->Int)-> func(x:Int)->Int +func mul_func(n:Int, fn:func(x:Int)->Int)-> func(x:Int)->Int: return func(x:Int) n*fn(x) -func main() +func main(): >> add_one := func(x:Int) x + 1 >> add_one(10) = 11 diff --git a/test/lang.tm b/test/lang.tm index ad09b605..3dea6ded 100644 --- a/test/lang.tm +++ b/test/lang.tm @@ -1,6 +1,6 @@ -lang HTML +lang HTML: HEADER := $HTML{}"" - func escape(t:Text)->HTML + func escape(t:Text)->HTML: t = t:replace("&", "&") t = t:replace("<", "<") t = t:replace(">", ">") @@ -8,13 +8,13 @@ lang HTML t = t:replace("'", "'") return HTML.from_unsafe_text(t) - func escape_int(i:Int)->HTML + func escape_int(i:Int)->HTML: return HTML.from_unsafe_text("{i}") - func paragraph(content:HTML)->HTML + func paragraph(content:HTML)->HTML: return $HTML{}"

{content}

" -func main() +func main(): >> HTML.HEADER = $HTML"" diff --git a/test/minmax.tm b/test/minmax.tm index c3af68d6..c2f070f6 100644 --- a/test/minmax.tm +++ b/test/minmax.tm @@ -1,9 +1,9 @@ -struct Foo(x:Int, y:Int) - func len(f:Foo)->Num +struct Foo(x:Int, y:Int): + func len(f:Foo)->Num: return Num.sqrt(f.x*f.x + f.y*f.y) -func main() +func main(): >> 3 _min_ 5 = 3 >> 5 _min_ 3 diff --git a/test/nums.tm b/test/nums.tm index 4e9c81a4..94959744 100644 --- a/test/nums.tm +++ b/test/nums.tm @@ -1,4 +1,4 @@ -func main() +func main(): >> n := 1.5 = 1.5 diff --git a/test/reductions.tm b/test/reductions.tm index 6ed7823f..97ec4afc 100644 --- a/test/reductions.tm +++ b/test/reductions.tm @@ -1,6 +1,6 @@ struct Foo(x,y:Int) -func main() +func main(): >> (+) [10, 20, 30] = 60 diff --git a/test/structs.tm b/test/structs.tm index 9fe2f6a7..840ee847 100644 --- a/test/structs.tm +++ b/test/structs.tm @@ -4,7 +4,7 @@ struct Mixed(x:Int, text:Text) struct LinkedList(x:Int, next=!LinkedList) struct Password(text:Text; secret) -func test_literals() +func test_literals(): >> x := Pair(10, 20) = Pair(x=10, y=20) >> y := Pair(y=20, 10) @@ -14,7 +14,7 @@ func test_literals() >> x == Pair(-1, -2) = no -func test_metamethods() +func test_metamethods(): >> x := Pair(10, 20) >> y := Pair(100, 200) >> x == y @@ -32,7 +32,7 @@ func test_metamethods() >> t2[y] = "missing" -func test_mixed() +func test_mixed(): >> x := Mixed(10, "Hello") >> y := Mixed(99, "Hello") >> x == y @@ -49,7 +49,7 @@ func test_mixed() >> t[y] = "missing" -func main() +func main(): test_literals() test_metamethods() test_mixed() diff --git a/test/tables.tm b/test/tables.tm index 2ba42714..8609e522 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -1,4 +1,4 @@ -func main() +func main(): >> t := {"one":1, "two":2; default=999} = {"one":1, "two":2; default=999} @@ -10,7 +10,7 @@ func main() = 999 t_str := "" - for k,v in t + for k,v in t: t_str ++= "({k}:{v})" >> t_str = "(one:1)(two:2)" @@ -45,7 +45,7 @@ func main() = ?%{"one":1, "two":2; default=999} t2_str := "" - for k,v in t2 + for k,v in t2: t2_str ++= "({k}:{v})" >> t2_str = "(three:3)" diff --git a/test/text.tm b/test/text.tm index bb2cc14a..9c451b89 100644 --- a/test/text.tm +++ b/test/text.tm @@ -1,4 +1,4 @@ -func main() +func main(): >> str := "Hello Amélie!" >> str:upper() = "HELLO AMÉLIE!" diff --git a/test/use.tm b/test/use.tm index a759180a..95ab3c7e 100644 --- a/test/use.tm +++ b/test/use.tm @@ -1,9 +1,9 @@ imported := use ./use_import -func asdf()->imported.ImportedType +func asdf()->imported.ImportedType: return imported.get_value() -func main() +func main(): >> [:imported.ImportedType] >> asdf() = ImportedType(name="Hello") diff --git a/test/use_import.tm b/test/use_import.tm index fb5f71e9..3b8e6743 100644 --- a/test/use_import.tm +++ b/test/use_import.tm @@ -1,7 +1,7 @@ struct ImportedType(name:Text) -func get_value()->ImportedType +func get_value()->ImportedType: return ImportedType("Hello") -func main() +func main(): pass -- cgit v1.2.3