aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/learnxiny.tm11
-rw-r--r--examples/log/log.tm2
-rw-r--r--examples/tomodeps/tomodeps.tm30
3 files changed, 22 insertions, 21 deletions
diff --git a/examples/learnxiny.tm b/examples/learnxiny.tm
index 6a3b7e21..74cba5df 100644
--- a/examples/learnxiny.tm
+++ b/examples/learnxiny.tm
@@ -159,20 +159,20 @@ func main():
# Sets are similar to tables, but they represent an unordered collection of
# unique values:
- set := {10, 20, 30}
+ set := |10, 20, 30|
>> set.has(20)
= yes
>> set.has(999)
= no
# You can do some operations on sets:
- other_set := {30, 40, 50}
+ other_set := |30, 40, 50|
>> set.with(other_set)
- = {10, 20, 30, 40, 50}
+ = |10, 20, 30, 40, 50|
>> set.without(other_set)
- = {10, 20}
+ = |10, 20|
>> set.overlap(other_set)
- = {30}
+ = |30|
# So far, the datastructures that have been discussed are all *immutable*,
# meaning you can't add, remove, or change their contents. If you want to
@@ -241,6 +241,7 @@ func takes_many_types(
text_aka_string:Text,
array_of_ints:[Int],
table_of_text_to_bools:{Text=Bool},
+ set_of_ints:|Int|,
pointer_to_mutable_array_of_ints:@[Int],
optional_int:Int?,
function_from_int_to_text:func(x:Int -> Text),
diff --git a/examples/log/log.tm b/examples/log/log.tm
index 7375d5f6..047398b0 100644
--- a/examples/log/log.tm
+++ b/examples/log/log.tm
@@ -3,7 +3,7 @@ use <stdio.h>
timestamp_format := CString("%F %T")
-logfiles : @{Path} = @{/}
+logfiles : @|Path| = @||
func _timestamp(->Text):
c_str := inline C:CString {
diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm
index dd7bec10..66bb74bd 100644
--- a/examples/tomodeps/tomodeps.tm
+++ b/examples/tomodeps/tomodeps.tm
@@ -11,12 +11,12 @@ _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():
say("Could not read file: $file")
- return {/}
+ return ||
- deps : @{Dependency} = @{/}
+ deps : @|Dependency| = @||
if lines := file.by_line():
for line in lines:
if line.matches_pattern($Pat/use {..}.tm/):
@@ -27,18 +27,18 @@ 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:@{Dependency=|Dependency|}):
return if dependencies.has(dep)
- dependencies[dep] = {/} # Placeholder
+ dependencies[dep] = || # Placeholder
dep_deps := when dep is File(path):
_get_file_dependencies(path)
is Module(module):
dir := (~/.local/share/tomo/installed/$module)
- module_deps : @{Dependency} = @{/}
- visited : @{Path} = @{/}
- unvisited := @{f.resolved() for f in dir.files() if f.extension() == ".tm"}
+ module_deps : @|Dependency| = @||
+ visited : @|Path| = @||
+ unvisited := @|f.resolved() for f in dir.files() if f.extension() == ".tm"|
while unvisited.length > 0:
file := unvisited.items[-1]
unvisited.remove(file)
@@ -57,8 +57,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 -> {Dependency=|Dependency|}):
+ graph : @{Dependency=|Dependency|} = @{}
_build_dependency_graph(dep, graph)
return graph
@@ -72,7 +72,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:{Dependency=|Dependency|}, already_printed:@|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
@@ -82,16 +82,16 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency={Dependency}}, already_
child_prefix := prefix ++ (if is_last: " " else: "│ ")
- children := dependencies[dep] or {/}
+ children := dependencies[dep] or ||
for i,child in children.items:
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}}):
- printed : @{Dependency} = @{/}
+func draw_tree(dep:Dependency, dependencies:{Dependency=|Dependency|}):
+ printed : @|Dependency| = @||
say(_printable_name(dep))
printed.add(dep)
- deps := dependencies[dep] or {/}
+ deps := dependencies[dep] or ||
for i,child in deps.items:
is_child_last := (i == deps.length)
_draw_tree(child, dependencies, already_printed=printed, is_last=is_child_last)