From 074cf22ad462eafe963e4a749b2b74cab51211a1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 9 Oct 2024 13:26:28 -0400 Subject: Change function syntax from `func(args)->ret` to `func(args -> ret)` --- examples/game/game.tm | 6 ++-- examples/game/world.tm | 2 +- examples/http/http.tm | 10 +++--- examples/ini/ini.tm | 2 +- examples/learnxiny.tm | 10 +++--- examples/log/log.tm | 2 +- examples/tomodeps/tomodeps.tm | 6 ++-- examples/vectors/vectors.tm | 84 +++++++++++++++++++++---------------------- examples/wrap/wrap.tm | 6 ++-- 9 files changed, 64 insertions(+), 64 deletions(-) (limited to 'examples') diff --git a/examples/game/game.tm b/examples/game/game.tm index c7d843e3..81aed45f 100644 --- a/examples/game/game.tm +++ b/examples/game/game.tm @@ -6,7 +6,7 @@ use use ./world.tm func main(map=(./map.txt)): - extern InitWindow:func(w:Int32, h:Int32, title:CString)->Void + extern InitWindow:func(w:Int32, h:Int32, title:CString) InitWindow(1600, 900, "raylib [core] example - 2d camera") map_contents := map:read() or exit("Could not find the game map: $map") @@ -16,10 +16,10 @@ func main(map=(./map.txt)): extern SetTargetFPS:func(fps:Int32) SetTargetFPS(60) - extern WindowShouldClose:func()->Bool + extern WindowShouldClose:func(->Bool) while not WindowShouldClose(): - extern GetFrameTime:func()->Num32 + extern GetFrameTime:func(->Num32) dt := GetFrameTime() World.CURRENT:update(Num(dt)) diff --git a/examples/game/world.tm b/examples/game/world.tm index 6208d1c5..71c14bfd 100644 --- a/examples/game/world.tm +++ b/examples/game/world.tm @@ -6,7 +6,7 @@ use ./color.tm use ./box.tm # Return a displacement relative to `a` that will push it out of `b` -func solve_overlap(a_pos:Vec2, a_size:Vec2, b_pos:Vec2, b_size:Vec2)->Vec2: +func solve_overlap(a_pos:Vec2, a_size:Vec2, b_pos:Vec2, b_size:Vec2 -> Vec2): a_left := a_pos.x a_right := a_pos.x + a_size.x a_top := a_pos.y diff --git a/examples/http/http.tm b/examples/http/http.tm index a4ded7d7..a1bcccc6 100644 --- a/examples/http/http.tm +++ b/examples/http/http.tm @@ -7,7 +7,7 @@ struct HTTPResponse(code:Int, body:Text) enum _Method(GET, POST, PUT, PATCH, DELETE) -func _send(method:_Method, url:Text, data:Text?, headers=[:Text])->HTTPResponse: +func _send(method:_Method, url:Text, data:Text?, headers=[:Text] -> HTTPResponse): chunks := @[:Text] save_chunk := func(chunk:CString, size:Int64, n:Int64): chunks:insert(inline C:Text { @@ -69,16 +69,16 @@ func _send(method:_Method, url:Text, data:Text?, headers=[:Text])->HTTPResponse: } return HTTPResponse(code, "":join(chunks)) -func get(url:Text, headers=[:Text])->HTTPResponse: +func get(url:Text, headers=[:Text] -> HTTPResponse): return _send(GET, url, !Text, headers) -func post(url:Text, data="", headers=["Content-Type: application/json", "Accept: application/json"])->HTTPResponse: +func post(url:Text, data="", headers=["Content-Type: application/json", "Accept: application/json"] -> HTTPResponse): return _send(POST, url, data, headers) -func put(url:Text, data="", headers=["Content-Type: application/json", "Accept: application/json"])->HTTPResponse: +func put(url:Text, data="", headers=["Content-Type: application/json", "Accept: application/json"] -> HTTPResponse): return _send(PUT, url, data, headers) -func delete(url:Text, data=!Text, headers=["Content-Type: application/json", "Accept: application/json"])->HTTPResponse: +func delete(url:Text, data=!Text, headers=["Content-Type: application/json", "Accept: application/json"] -> HTTPResponse): return _send(DELETE, url, data, headers) func main(): diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm index 37692cae..4e5ec776 100644 --- a/examples/ini/ini.tm +++ b/examples/ini/ini.tm @@ -6,7 +6,7 @@ _HELP := " $_USAGE " -func parse_ini(path:Path)->{Text:{Text:Text}}: +func parse_ini(path:Path -> {Text:{Text:Text}}): text := path:read() or exit("Could not read INI file: $\[31;1]$(path.text_content)$\[]") sections := {:Text:@{Text:Text}} current_section := @{:Text:Text} diff --git a/examples/learnxiny.tm b/examples/learnxiny.tm index f003167f..ed8e2596 100644 --- a/examples/learnxiny.tm +++ b/examples/learnxiny.tm @@ -211,12 +211,12 @@ func main(): # Functions must be declared at the top level of a file and must specify the # types of all of their arguments and return value (if any): -func add(x:Int, y:Int)->Int: +func add(x:Int, y:Int -> Int): return x + y # Default values for arguments can be provided in place of a type (the type is # inferred from the default value): -func show_both(first:Int, second=0)->Text: +func show_both(first:Int, second=0 -> Text): return "first=$first second=$second" func demo_keyword_args(): @@ -241,7 +241,7 @@ func takes_many_types( table_of_text_to_bools:{Text:Bool}, pointer_to_mutable_array_of_ints:@[Int], optional_int:Int?, - function_from_int_to_text:func(x:Int)->Text, + function_from_int_to_text:func(x:Int -> Text), ): pass @@ -259,7 +259,7 @@ struct Person(name:Text, age:Int): self.age += amount # Methods don't have to take a Person as their first argument: - func get_cool_name()->Text: + func get_cool_name(->Text): return "Blade" func demo_structs(): @@ -304,7 +304,7 @@ enum Shape( ): # Just like with structs, you define methods and constants inside a level # of indentation: - func get_area(self:Shape)->Num: + func get_area(self:Shape->Num): # In order to work with an enum, it's most often handy to use a 'when' # statement to get the internal values: when self is Point: diff --git a/examples/log/log.tm b/examples/log/log.tm index 42df072c..f537b850 100644 --- a/examples/log/log.tm +++ b/examples/log/log.tm @@ -5,7 +5,7 @@ timestamp_format := CString("%F %T") logfiles := {:Path} -func _timestamp()->Text: +func _timestamp(->Text): c_str := inline C:CString { char *str = GC_MALLOC_ATOMIC(20); time_t t; time(&t); diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm index 9418ba6f..907734a0 100644 --- a/examples/tomodeps/tomodeps.tm +++ b/examples/tomodeps/tomodeps.tm @@ -9,7 +9,7 @@ _HELP := " enum Dependency(File(path:Path), Module(name:Text)) -func _get_file_dependencies(file:Path)->{Dependency}: +func _get_file_dependencies(file:Path -> {Dependency}): if not file:is_file(): !! Could not read file: $file return {:Dependency} @@ -55,12 +55,12 @@ func _build_dependency_graph(dep:Dependency, dependencies:&{Dependency:{Dependen for dep2 in dep_deps: _build_dependency_graph(dep2, dependencies) -func get_dependency_graph(dep:Dependency)->{Dependency:{Dependency}}: +func get_dependency_graph(dep:Dependency -> {Dependency:{Dependency}}): graph := {:Dependency:{Dependency}} _build_dependency_graph(dep, &graph) return graph -func _printable_name(dep:Dependency)->Text: +func _printable_name(dep:Dependency -> Text): when dep is Module(module): return "$(\x1b)[34;1m$module$(\x1b)[m" is File(f): diff --git a/examples/vectors/vectors.tm b/examples/vectors/vectors.tm index 8560f9df..696bef1e 100644 --- a/examples/vectors/vectors.tm +++ b/examples/vectors/vectors.tm @@ -2,32 +2,32 @@ struct Vec2(x,y:Num): ZERO := Vec2(0, 0) - func plus(a,b:Vec2; inline)->Vec2: + func plus(a,b:Vec2->Vec2; inline): return Vec2(a.x+b.x, a.y+b.y) - func minus(a,b:Vec2; inline)->Vec2: + func minus(a,b:Vec2->Vec2; inline): return Vec2(a.x-b.x, a.y-b.y) - func times(a,b:Vec2; inline)->Vec2: + func times(a,b:Vec2->Vec2; inline): return Vec2(a.x*b.x, a.y*b.y) - func dot(a,b:Vec2; inline)->Num: + func dot(a,b:Vec2->Num; inline): return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) - func cross(a,b:Vec2; inline)->Num: + func cross(a,b:Vec2->Num; inline): return a.x*b.y - a.y*b.x - func scaled_by(v:Vec2, k:Num; inline)->Vec2: + func scaled_by(v:Vec2, k:Num->Vec2; inline): return Vec2(v.x*k, v.y*k) - func divided_by(v:Vec2, divisor:Num; inline)->Vec2: + func divided_by(v:Vec2, divisor:Num->Vec2; inline): return Vec2(v.x/divisor, v.y/divisor) - func length(v:Vec2; inline)->Num: + func length(v:Vec2->Num; inline): return (v.x*v.x + v.y*v.y):sqrt() - func dist(a,b:Vec2; inline)->Num: + func dist(a,b:Vec2->Num; inline): return a:minus(b):length() - func angle(v:Vec2; inline)->Num: + func angle(v:Vec2->Num; inline): return Num.atan2(v.y, v.x) - func norm(v:Vec2; inline)->Vec2: + func norm(v:Vec2->Vec2; inline): if v.x == 0 and v.y == 0: return v len := v:length() return Vec2(v.x/len, v.y/len) - func mix(a,b:Vec2, amount:Num)->Vec2: + func mix(a,b:Vec2, amount:Num -> Vec2): return Vec2( amount:mix(a.x, b.x), amount:mix(a.y, b.y), @@ -35,30 +35,30 @@ struct Vec2(x,y:Num): struct Vec3(x,y,z:Num): ZERO := Vec3(0, 0, 0) - func plus(a,b:Vec3; inline)->Vec3: + func plus(a,b:Vec3->Vec3; inline): return Vec3(a.x+b.x, a.y+b.y, a.z+b.z) - func minus(a,b:Vec3; inline)->Vec3: + func minus(a,b:Vec3->Vec3; inline): return Vec3(a.x-b.x, a.y-b.y, a.z-b.z) - func times(a,b:Vec3; inline)->Vec3: + func times(a,b:Vec3->Vec3; inline): return Vec3(a.x*b.x, a.y*b.y, a.z*b.z) - func dot(a,b:Vec3; inline)->Num: + func dot(a,b:Vec3->Num; inline): return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z) - func cross(a,b:Vec3; inline)->Vec3: + func cross(a,b:Vec3->Vec3; inline): return Vec3(a.y*b.z - a.z-b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x) - func scaled_by(v:Vec3, k:Num; inline)->Vec3: + func scaled_by(v:Vec3, k:Num->Vec3; inline): return Vec3(v.x*k, v.y*k, v.z*k) - func divided_by(v:Vec3, divisor:Num; inline)->Vec3: + func divided_by(v:Vec3, divisor:Num->Vec3; inline): return Vec3(v.x/divisor, v.y/divisor, v.z/divisor) - func length(v:Vec3; inline)->Num: + func length(v:Vec3->Num; inline): return (v.x*v.x + v.y*v.y + v.z*v.z):sqrt() - func dist(a,b:Vec3; inline)->Num: + func dist(a,b:Vec3->Num; inline): return a:minus(b):length() - func norm(v:Vec3; inline)->Vec3: + func norm(v:Vec3->Vec3; inline): if v.x == 0 and v.y == 0 and v.z == 0: return v len := v:length() return Vec3(v.x/len, v.y/len, v.z/len) - func mix(a,b:Vec3, amount:Num)->Vec3: + func mix(a,b:Vec3, amount:Num -> Vec3): return Vec3( amount:mix(a.x, b.x), amount:mix(a.y, b.y), @@ -68,46 +68,46 @@ struct Vec3(x,y,z:Num): struct IVec2(x,y:Int): ZERO := IVec2(0, 0) - func plus(a,b:IVec2; inline)->IVec2: + func plus(a,b:IVec2->IVec2; inline): return IVec2(a.x+b.x, a.y+b.y) - func minus(a,b:IVec2; inline)->IVec2: + func minus(a,b:IVec2->IVec2; inline): return IVec2(a.x-b.x, a.y-b.y) - func times(a,b:IVec2; inline)->IVec2: + func times(a,b:IVec2->IVec2; inline): return IVec2(a.x*b.x, a.y*b.y) - func dot(a,b:IVec2; inline)->Int: + func dot(a,b:IVec2->Int; inline): return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) - func cross(a,b:IVec2; inline)->Int: + func cross(a,b:IVec2->Int; inline): return a.x*b.y - a.y*b.x - func scaled_by(v:IVec2, k:Int; inline)->IVec2: + func scaled_by(v:IVec2, k:Int->IVec2; inline): return IVec2(v.x*k, v.y*k) - func divided_by(v:IVec2, divisor:Int; inline)->IVec2: + func divided_by(v:IVec2, divisor:Int->IVec2; inline): return IVec2(v.x/divisor, v.y/divisor) - func length(v:IVec2; inline)->Num: + func length(v:IVec2->Num; inline): return Num.sqrt(v.x*v.x + v.y*v.y) - func dist(a,b:IVec2; inline)->Num: + func dist(a,b:IVec2->Num; inline): return a:minus(b):length() - func angle(v:IVec2; inline)->Num: + func angle(v:IVec2->Num; inline): return Num.atan2(v.y, v.x) struct IVec3(x,y,z:Int): ZERO := IVec3(0, 0, 0) - func plus(a,b:IVec3; inline)->IVec3: + func plus(a,b:IVec3->IVec3; inline): return IVec3(a.x+b.x, a.y+b.y, a.z+b.z) - func minus(a,b:IVec3; inline)->IVec3: + func minus(a,b:IVec3->IVec3; inline): return IVec3(a.x-b.x, a.y-b.y, a.z-b.z) - func times(a,b:IVec3; inline)->IVec3: + func times(a,b:IVec3->IVec3; inline): return IVec3(a.x*b.x, a.y*b.y, a.z*b.z) - func dot(a,b:IVec3; inline)->Int: + func dot(a,b:IVec3->Int; inline): return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z) - func cross(a,b:IVec3; inline)->IVec3: + func cross(a,b:IVec3->IVec3; inline): return IVec3(a.y*b.z - a.z-b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x) - func scaled_by(v:IVec3, k:Int; inline)->IVec3: + func scaled_by(v:IVec3, k:Int->IVec3; inline): return IVec3(v.x*k, v.y*k, v.z*k) - func divided_by(v:IVec3, divisor:Int; inline)->IVec3: + func divided_by(v:IVec3, divisor:Int->IVec3; inline): return IVec3(v.x/divisor, v.y/divisor, v.z/divisor) - func length(v:IVec3; inline)->Num: + func length(v:IVec3->Num; inline): return Num.sqrt(v.x*v.x + v.y*v.y + v.z*v.z) - func dist(a,b:IVec3; inline)->Num: + func dist(a,b:IVec3->Num; inline): return a:minus(b):length() func main(): diff --git a/examples/wrap/wrap.tm b/examples/wrap/wrap.tm index a89d8b41..ced8aab1 100644 --- a/examples/wrap/wrap.tm +++ b/examples/wrap/wrap.tm @@ -13,7 +13,7 @@ HELP := " UNICODE_HYPHEN := \{hyphen} -func unwrap(text:Text, preserve_paragraphs=yes, hyphen=UNICODE_HYPHEN)->Text: +func unwrap(text:Text, preserve_paragraphs=yes, hyphen=UNICODE_HYPHEN -> Text): if preserve_paragraphs: paragraphs := text:split($/{2+ nl}/) if paragraphs.length > 1: @@ -21,7 +21,7 @@ func unwrap(text:Text, preserve_paragraphs=yes, hyphen=UNICODE_HYPHEN)->Text: return text:replace($/$(hyphen)$(\n)/, "") -func wrap(text:Text, width:Int, min_split=3, hyphen="-")->Text: +func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text): if width <= 0: fail("Width must be a positive integer, not $width") @@ -71,7 +71,7 @@ func wrap(text:Text, width:Int, min_split=3, hyphen="-")->Text: return \n:join(lines) -func _can_fit_word(line:Text, letters:[Text], width:Int; inline)->Bool: +func _can_fit_word(line:Text, letters:[Text], width:Int -> Bool; inline): if line == "": return letters.length <= width else: -- cgit v1.2.3