aboutsummaryrefslogtreecommitdiff
path: root/test/for.tm
blob: 9c329c62abb336d8215043407feb0c4ced84ec3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

func all_nums(nums:[Int] -> Text)
	result := ""
	for num in nums
		result ++= "$num,"
	else
		return "EMPTY"
	return result

func labeled_nums(nums:[Int] -> Text)
	result := ""
	for i,num in nums
		result ++= "$i:$num,"
	else
		return "EMPTY"
	return result

func table_str(t:{Text:Text} -> Text)
	str := ""
	for k,v in t
		str ++= "$k:$v,"
	else return "EMPTY"
	return str

func table_key_str(t:{Text:Text} -> Text)
	str := ""
	for k in t
		str ++= "$k,"
	else return "EMPTY"
	return str

func main()
	>> all_nums([10,20,30])
	= "10,20,30,"
	>> all_nums([])
	= "EMPTY"

	>> labeled_nums([10,20,30])
	= "1:10,2:20,3:30,"
	>> labeled_nums([])
	= "EMPTY"

	>> t := {"key1":"value1", "key2":"value2"}
	>> table_str(t)
	= "key1:value1,key2:value2,"
	>> table_str({})
	= "EMPTY"

	>> table_key_str(t)
	= "key1,key2,"