summaryrefslogtreecommitdiff
path: root/spec/inputs/vararg.yue
blob: 4f8a0d7cf7fce51e08f3c99cd299888ce3d67fc7 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
join = (...) ->
	f_with with a
		\func!
	f_with with a
		\func ...

	f_listcomp [items[i] for i = 1, 10]
	f_listcomp [items[i] ... for i = 1, 10]
	f_listcomp [item for item in *items]
	f_listcomp [item ... for item in *items]

	f_class class A
		func!
	f_class class A
		func ...

	f_tblcomp {k, v for k, v in pairs tb}
	f_tblcomp {k, v ... for k, v in pairs tb}
	f_tblcomp {item, true for item in *items}
	f_tblcomp {item(...), true for item in *items}

	f_do do
		func!
	f_do do
		func ...

	f_while while false
		func!
	f_while while false
		func ...

	f_if if false
		func!
	f_if if false
		func ...

	f_unless unless true
		func!
	f_unless unless true
		func ...

	f_switch switch x
		when "abc"
			func!
	f_switch switch x
		when "abc"
			func ...

	f_eop func?!
	f_eop func? ...

	f_colon f!\func
	f_colon f(...)\func

	_ = ->
		list = {1, 2, 3, 4, 5}
		fn = (ok) ->
			ok, table.unpack list
		ok, ... = fn true
		print ok, ...

		fn_many_args = ->
			10, nil, 20, nil, 30

		... = fn_many_args!
		print select "#", ...
		print ...

	do
		... = switch x when 1
			with tb
				.x = 123
		else
			tb2
		print ...

	do
		... = 1, 2, if cond
			3, 4, 5
		print ...

	do
		tb, ... =
			name: "abc"
			value: 123
		print ...
	nil

do
	f1 = (...t) ->
		print t.n
		print #t
		for i = 1, t.n
			print t[i]

	f1 1, 2, 3
	f1 "a", "b", "c", "d"
	f1!

	f2 = (...args) ->
		print "args count:", args.n
		print "args length:", #args
		for i = 1, args.n
			if args[i] == nil
				print "position", i, "is nil"
			else
				print "position", i, ":", args[i]

	f2 1, nil, 3, nil, 5

	f3 = (prefix, ...items) ->
		result = {}
		for i = 1, items.n
			result[i] = prefix .. tostring items[i]
		result

	f3 "item_", 1, 2, 3

	f4 = (...empty) ->
		print "empty count:", empty.n
		print "empty length:", #empty

	f4!

	process = (...data) ->
		sum = 0
		for i = 1, data.n
			if type(data[i]) == "number"
				sum += data[i]
		sum

	process 1, 2, 3, "skip", 5