tomo/test/for.tm

51 lines
844 B
Plaintext
Raw Normal View History

2024-03-07 09:07:14 -08:00
func all_nums(nums:[Int] -> Text):
2024-03-07 09:07:14 -08:00
result := ""
2024-04-28 11:58:55 -07:00
for num in nums:
result ++= "$num,"
2024-04-28 11:58:55 -07:00
else:
2024-03-07 09:07:14 -08:00
return "EMPTY"
return result
func labeled_nums(nums:[Int] -> Text):
2024-03-07 09:07:14 -08:00
result := ""
2024-04-28 11:58:55 -07:00
for i,num in nums:
result ++= "$i:$num,"
2024-04-28 11:58:55 -07:00
else:
2024-03-07 09:07:14 -08:00
return "EMPTY"
return result
func table_str(t:{Text=Text} -> Text):
2024-03-07 09:07:14 -08:00
str := ""
2024-04-28 11:58:55 -07:00
for k,v in t:
str ++= "$k:$v,"
2024-04-28 11:58:55 -07:00
else: return "EMPTY"
2024-03-07 09:07:14 -08:00
return str
func table_key_str(t:{Text=Text} -> Text):
2024-03-07 09:07:14 -08:00
str := ""
2024-04-28 11:58:55 -07:00
for k in t:
str ++= "$k,"
2024-04-28 11:58:55 -07:00
else: return "EMPTY"
2024-03-07 09:07:14 -08:00
return str
2024-04-28 11:58:55 -07:00
func main():
2024-04-12 10:09:31 -07:00
>> all_nums([10,20,30])
= "10,20,30,"
>> all_nums([:Int])
= "EMPTY"
>> labeled_nums([10,20,30])
= "1:10,2:20,3:30,"
>> labeled_nums([:Int])
= "EMPTY"
>> t := {"key1"="value1", "key2"="value2"}
2024-04-12 10:09:31 -07:00
>> table_str(t)
= "key1:value1,key2:value2,"
>> table_str({:Text=Text})
2024-04-12 10:09:31 -07:00
= "EMPTY"
>> table_key_str(t)
= "key1,key2,"