aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 16:49:40 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 16:49:40 -0400
commite87e6dabfbdc1d35b5fe41b5d84dab38df3c8e76 (patch)
tree93588c81392489a621ce4fcca41645c92c0d06e9
parentf69f862bf6e744834d781867a85f962c783f314e (diff)
Insert `then` for clarity
-rw-r--r--examples/colorful/colorful.tm2
-rw-r--r--examples/tomodeps/tomodeps.tm6
-rw-r--r--examples/wrap/wrap.tm8
-rw-r--r--test/optionals.tm2
-rw-r--r--test/paths.tm4
-rw-r--r--test/when.tm9
6 files changed, 14 insertions, 17 deletions
diff --git a/examples/colorful/colorful.tm b/examples/colorful/colorful.tm
index d64afe6e..d878b662 100644
--- a/examples/colorful/colorful.tm
+++ b/examples/colorful/colorful.tm
@@ -28,7 +28,7 @@ func main(texts:[Text], files:[Path]=[], by_line=no)
for i,text in texts
colorful := Colorful.from_text(text)
colorful.print(newline=no)
- if i == texts.length say("")
+ if i == texts.length then say("")
else say(" ", newline=no)
if texts.length == 0 and files.length == 0
diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm
index 1aafa6bd..1181f2be 100644
--- a/examples/tomodeps/tomodeps.tm
+++ b/examples/tomodeps/tomodeps.tm
@@ -74,13 +74,13 @@ func _printable_name(dep:Dependency -> Text)
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")
+ say(prefix ++ (if is_last then "└── " else "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m")
return
- say(prefix ++ (if is_last "└── " else "├── ") ++ _printable_name(dep))
+ say(prefix ++ (if is_last then "└── " else "├── ") ++ _printable_name(dep))
already_printed.add(dep)
- child_prefix := prefix ++ (if is_last " " else "│ ")
+ child_prefix := prefix ++ (if is_last then " " else "│ ")
children := dependencies[dep] or ||
for i,child in children.items
diff --git a/examples/wrap/wrap.tm b/examples/wrap/wrap.tm
index c539a0ea..303393ee 100644
--- a/examples/wrap/wrap.tm
+++ b/examples/wrap/wrap.tm
@@ -41,19 +41,19 @@ func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text)
while not _can_fit_word(line, letters, width)
line_space := width - line.length
- if line != "" line_space -= 1
+ if line != "" then line_space -= 1
if min_split > 0 and line_space >= min_split + hyphen.length and letters.length >= 2*min_split
# Split word with a hyphen:
split := line_space - hyphen.length
split = split _max_ min_split
split = split _min_ (letters.length - min_split)
- if line != "" line ++= " "
+ if line != "" then line ++= " "
line ++= ((++: letters.to(split)) or "") ++ hyphen
letters = letters.from(split + 1)
else if line == ""
# Force split word without hyphenation:
- if line != "" line ++= " "
+ if line != "" then line ++= " "
line ++= (++: letters.to(line_space)) or ""
letters = letters.from(line_space + 1)
else
@@ -63,7 +63,7 @@ func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text)
line = ""
if letters.length > 0
- if line != "" line ++= " "
+ if line != "" then line ++= " "
line ++= (++: letters) or ""
if line != ""
diff --git a/test/optionals.tm b/test/optionals.tm
index 5344848d..36f38625 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -259,7 +259,7 @@ func main()
= 5
do
- >> value := if var : Int? = none
+ >> value := if var : Int? = none then
var
else
0
diff --git a/test/paths.tm b/test/paths.tm
index 700a0393..7685d089 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -29,7 +29,7 @@ func main()
>> tmpdir.files().has(tmpfile)
= yes
- if tmp_lines := tmpfile.by_line()
+ if tmp_lines := tmpfile.by_line() then
>> [line for line in tmp_lines]
= ["Hello world!"]
else
@@ -39,7 +39,7 @@ func main()
= none
>> (./does-not-exist.xxx).read_bytes()
= none
- if lines := (./does-not-exist.xxx).by_line()
+ if lines := (./does-not-exist.xxx).by_line() then
fail("I could read lines in a nonexistent file")
else
pass
diff --git a/test/when.tm b/test/when.tm
index 28573d88..d18f5276 100644
--- a/test/when.tm
+++ b/test/when.tm
@@ -3,12 +3,9 @@
func main()
answers := [
(
- when x is "A","B"
- "A or B"
- is "C"
- "C"
- else
- "Other"
+ when x is "A","B" then "A or B"
+ is "C" then "C"
+ else "Other"
) for x in ["A", "B", "C", "D"]
]
>> answers