aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-17 22:18:21 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-17 22:18:21 -0400
commitca62aa365faee27895f8cb1eccddd7af8a7d15c9 (patch)
tree22d191de7f16c889c407ef92f27ef9efb3303998 /examples
parent80ca0f0b1ba04c1aa3d7bb1a62928dbcecbb3bd8 (diff)
Switch types to use wordier syntax `[T]` -> `List(T)` etc
Diffstat (limited to 'examples')
-rw-r--r--examples/base64/base64.tm4
-rw-r--r--examples/colorful/colorful.tm6
-rw-r--r--examples/commands/commands.tm8
-rw-r--r--examples/game/world.tm2
-rw-r--r--examples/ini/ini.tm4
-rw-r--r--examples/learnxiny.tm6
-rw-r--r--examples/pthread/pthread.tm2
-rw-r--r--examples/shell/shell.tm6
-rw-r--r--examples/tomo-install/tomo-install.tm4
-rw-r--r--examples/tomodeps/tomodeps.tm14
-rw-r--r--examples/wrap/wrap.tm4
11 files changed, 30 insertions, 30 deletions
diff --git a/examples/base64/base64.tm b/examples/base64/base64.tm
index fadfed20..e2adc206 100644
--- a/examples/base64/base64.tm
+++ b/examples/base64/base64.tm
@@ -28,7 +28,7 @@ lang Base64:
func parse(text:Text -> Base64?):
return Base64.from_bytes(text:bytes())
- func from_bytes(bytes:[Byte] -> Base64?):
+ func from_bytes(bytes:List(Byte) -> Base64?):
output := &[Byte(0) for _ in bytes.length * 4 / 3 + 4]
src := Int64(1)
dest := Int64(1)
@@ -64,7 +64,7 @@ lang Base64:
func decode_text(b64:Base64 -> Text?):
return Text.from_bytes(b64:decode_bytes() or return none)
- func decode_bytes(b64:Base64 -> [Byte]?):
+ func decode_bytes(b64:Base64 -> List(Byte)?):
bytes := b64.text:bytes()
output := &[Byte(0) for _ in bytes.length/4 * 3]
src := Int64(1)
diff --git a/examples/colorful/colorful.tm b/examples/colorful/colorful.tm
index e5baf4ac..f0901ae2 100644
--- a/examples/colorful/colorful.tm
+++ b/examples/colorful/colorful.tm
@@ -21,7 +21,7 @@ lang Colorful:
say(c:for_terminal(), newline=newline)
-func main(texts:[Text], files=[:Path], by_line=no):
+func main(texts:List(Text), files=[:Path], by_line=no):
for i,text in texts:
colorful := Colorful.from_text(text)
colorful:print(newline=no)
@@ -113,13 +113,13 @@ enum _Color(Default, Bright(color:Int16), Color8Bit(color:Int16), Color24Bit(col
pass
fail("Invalid underline color: '$c'")
-func _toggle(sequences:&[Text], cur,new:Bool, apply,unapply:Text; inline):
+func _toggle(sequences:&List(Text), cur,new:Bool, apply,unapply:Text; inline):
if new and not cur:
sequences:insert(apply)
else if cur and not new:
sequences:insert(unapply)
-func _toggle2(sequences:&[Text], cur1,cur2,new1,new2:Bool, apply1,apply2,unapply:Text; inline):
+func _toggle2(sequences:&List(Text), cur1,cur2,new1,new2:Bool, apply1,apply2,unapply:Text; inline):
return if new1 == cur1 and new2 == cur2
if (cur1 and not new1) or (cur2 and not new2): # Gotta wipe at least one
sequences:insert(unapply)
diff --git a/examples/commands/commands.tm b/examples/commands/commands.tm
index a0e73908..4a6adeb0 100644
--- a/examples/commands/commands.tm
+++ b/examples/commands/commands.tm
@@ -2,11 +2,11 @@
use ./commands.c
-extern run_command:func(exe:Text, args:[Text], env:{Text,Text}, input:[Byte], output:&[Byte], error:&[Byte] -> Int32)
+extern run_command:func(exe:Text, args:List(Text), env:Table(Text,Text), input:List(Byte), output:&List(Byte), error:&List(Byte) -> Int32)
enum ExitType(Exited(status:Int32), Signaled(signal:Int32), Failed)
-struct ProgramResult(stdout:[Byte], stderr:[Byte], exit_type:ExitType):
+struct ProgramResult(stdout:List(Byte), stderr:List(Byte), exit_type:ExitType):
func or_fail(r:ProgramResult -> ProgramResult):
when r.exit_type is Exited(status):
if status == 0:
@@ -54,13 +54,13 @@ struct Command(command:Text, args=[:Text], env={:Text,Text}):
func get_output(command:Command, input="", trim_newline=yes -> Text?):
return command:run(input=input):output_text(trim_newline=trim_newline)
- func get_output_bytes(command:Command, input="", input_bytes=[:Byte] -> [Byte]?):
+ func get_output_bytes(command:Command, input="", input_bytes=[:Byte] -> List(Byte)?):
result := command:run(input=input, input_bytes=input_bytes)
when result.exit_type is Exited(status):
if status == 0: return result.stdout
return none
else: return none
-func main(command:Text, args:[Text], input=""):
+func main(command:Text, args:List(Text), input=""):
cmd := Command(command, args)
say(cmd:get_output(input=input)!)
diff --git a/examples/game/world.tm b/examples/game/world.tm
index 58fcd4fa..643ae7ae 100644
--- a/examples/game/world.tm
+++ b/examples/game/world.tm
@@ -37,7 +37,7 @@ func solve_overlap(a_pos:Vector2, a_size:Vector2, b_pos:Vector2, b_size:Vector2
return Vector2(0, 0)
-struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=no):
+struct World(player:@Player, goal:@Box, boxes:@List(@Box), dt_accum=Num32(0.0), won=no):
DT := (Num32(1.)/Num32(60.))!
STIFFNESS := Num32(0.3)
diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm
index 1c50ac37..e6f0a7e3 100644
--- a/examples/ini/ini.tm
+++ b/examples/ini/ini.tm
@@ -6,9 +6,9 @@ _HELP := "
$_USAGE
"
-func parse_ini(path:Path -> {Text,{Text,Text}}):
+func parse_ini(path:Path -> Table(Text, Table(Text, Text))):
text := path:read() or exit("Could not read INI file: $\[31;1]$(path)$\[]")
- sections := @{:Text,@{Text,Text}}
+ sections := @{:Text,@Table(Text, Text)}
current_section := @{:Text,Text}
# Line wraps:
diff --git a/examples/learnxiny.tm b/examples/learnxiny.tm
index e2058558..d015137d 100644
--- a/examples/learnxiny.tm
+++ b/examples/learnxiny.tm
@@ -242,9 +242,9 @@ func takes_many_types(
integer:Int,
floating_point_number:Num,
text_aka_string:Text,
- array_of_ints:[Int],
- table_of_text_to_bools:{Text,Bool},
- pointer_to_mutable_array_of_ints:@[Int],
+ array_of_ints:List(Int),
+ table_of_text_to_bools:Table(Text,Bool),
+ pointer_to_mutable_array_of_ints:@List(Int),
optional_int:Int?,
function_from_int_to_text:func(x:Int -> Text),
):
diff --git a/examples/pthread/pthread.tm b/examples/pthread/pthread.tm
index 13d94e40..e33d2b1f 100644
--- a/examples/pthread/pthread.tm
+++ b/examples/pthread/pthread.tm
@@ -53,7 +53,7 @@ struct pthread_t(; extern, opaque):
func cancel(p:@pthread_t): inline C { pthread_cancel(*_$p); }
func detatch(p:@pthread_t): inline C { pthread_detach(*_$p); }
-struct IntQueue(_queue:@[Int], _mutex:@pthread_mutex_t, _cond:@pthread_cond_t):
+struct IntQueue(_queue:@List(Int), _mutex:@pthread_mutex_t, _cond:@pthread_cond_t):
func new(initial=[:Int] -> IntQueue):
return IntQueue(@initial, pthread_mutex_t.new(), pthread_cond_t.new())
diff --git a/examples/shell/shell.tm b/examples/shell/shell.tm
index cf5fcd2e..86100912 100644
--- a/examples/shell/shell.tm
+++ b/examples/shell/shell.tm
@@ -4,13 +4,13 @@ lang Shell:
convert(text:Text -> Shell):
return Shell.from_text("'" ++ text:replace($/'/, `'"'"'`) ++ "'")
- convert(texts:[Text] -> Shell):
+ convert(texts:List(Text) -> Shell):
return Shell.from_text(" ":join([Shell(t).text for t in texts]))
convert(path:Path -> Shell):
return Shell(Text(path:expand_home()))
- convert(paths:[Path] -> Shell):
+ convert(paths:List(Path) -> Shell):
return Shell.from_text(" ":join([Shell(Text(p)).text for p in paths]))
convert(n:Int -> Shell): return Shell.from_text(Text(n))
@@ -30,6 +30,6 @@ lang Shell:
func get_output(shell:Shell, input="", trim_newline=yes -> Text?):
return shell:command():get_output(input=input, trim_newline=trim_newline)
- func get_output_bytes(shell:Shell, input="", input_bytes=[:Byte] -> [Byte]?):
+ func get_output_bytes(shell:Shell, input="", input_bytes=[:Byte] -> List(Byte)?):
return shell:command():get_output_bytes(input=input, input_bytes=input_bytes)
diff --git a/examples/tomo-install/tomo-install.tm b/examples/tomo-install/tomo-install.tm
index 0205c380..cd806f28 100644
--- a/examples/tomo-install/tomo-install.tm
+++ b/examples/tomo-install/tomo-install.tm
@@ -9,7 +9,7 @@ _HELP := "
Usage: $_USAGE
"
-func find_urls(path:Path -> [Text]):
+func find_urls(path:Path -> List(Text)):
urls := @[:Text]
if path:is_directory():
for f in path:children():
@@ -20,7 +20,7 @@ func find_urls(path:Path -> [Text]):
urls:insert(m[-1])
return urls
-func main(paths:[Path]):
+func main(paths:List(Path)):
if paths.length == 0:
paths = [(./)]
diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm
index 8149ff88..44ac6e45 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 -> Set(Dependency)):
if not file:is_file():
!! Could not read file: $file
return {:Dependency}
@@ -25,7 +25,7 @@ func _get_file_dependencies(file:Path -> {Dependency}):
deps:add(Dependency.Module(module_name))
return deps[]
-func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependency}}):
+func _build_dependency_graph(dep:Dependency, dependencies:@Table(Dependency,Set(Dependency))):
return if dependencies:has(dep)
dependencies[dep] = {:Dependency} # Placeholder
@@ -55,8 +55,8 @@ 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}}):
- graph := @{:Dependency,{Dependency}}
+func get_dependency_graph(dep:Dependency -> Table(Dependency, Set(Dependency))):
+ graph := @{:Dependency,Set(Dependency)}
_build_dependency_graph(dep, graph)
return graph
@@ -70,7 +70,7 @@ func _printable_name(dep:Dependency -> Text):
else:
return "$(\x1b)[31;1m$(f) (not found)$(\x1b)[m"
-func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_printed:@{Dependency}, prefix="", is_last=yes):
+func _draw_tree(dep:Dependency, dependencies:Table(Dependency,Set(Dependency)), already_printed:@Set(Dependency), prefix="", is_last=yes):
if already_printed:has(dep):
say(prefix ++ (if is_last: "└── " else: "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m")
return
@@ -85,7 +85,7 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_
is_child_last := (i == children.length)
_draw_tree(child, dependencies, already_printed, child_prefix, is_child_last)
-func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}):
+func draw_tree(dep:Dependency, dependencies:Table(Dependency,Set(Dependency))):
printed := @{:Dependency}
say(_printable_name(dep))
printed:add(dep)
@@ -94,7 +94,7 @@ func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}):
is_child_last := (i == deps.length)
_draw_tree(child, dependencies, already_printed=printed, is_last=is_child_last)
-func main(files:[Text]):
+func main(files:List(Text)):
if files.length == 0:
exit("
Please provide at least one file!
diff --git a/examples/wrap/wrap.tm b/examples/wrap/wrap.tm
index c90713a9..4040ee65 100644
--- a/examples/wrap/wrap.tm
+++ b/examples/wrap/wrap.tm
@@ -71,13 +71,13 @@ 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 -> Bool; inline):
+func _can_fit_word(line:Text, letters:List(Text), width:Int -> Bool; inline):
if line == "":
return letters.length <= width
else:
return line.length + 1 + letters.length <= width
-func main(files:[Path], width=80, inplace=no, min_split=3, rewrap=yes, hyphen=UNICODE_HYPHEN):
+func main(files:List(Path), width=80, inplace=no, min_split=3, rewrap=yes, hyphen=UNICODE_HYPHEN):
if files.length == 0:
files = [(/dev/stdin)]