summaryrefslogtreecommitdiff
path: root/spec/inputs/funcs.yue
blob: 6b1669b97162abd11579ed0b5954068383fc5047 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227


x = -> print what

_ = ->

_ = -> -> ->

go to the barn

open -> the -> door

open ->
	the door
	hello = ->
		my func

h = -> hi

eat ->, world


(->)()

x = (...) ->

hello!
hello.world!

_ = hello!.something
_ = what!["ofefe"]

what! the! heck!

_ = (a,b,c,d,e) ->

_ = (a,a,a,a,a) ->
	print a

_ = (x=23023) ->

_ = (x=(y=()->) ->) ->

_ = (x = if something then yeah else no) ->

something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") ->
	print hello

_ = () =>
_ = (x, y) =>
_ = (@x, @y) =>
_ = (x=1) =>
_ = (@x=1,y,@z="hello world") =>


x -> return
y -> return 1
z -> return 1, "hello", "world"
k -> if yes then return else return

_ = -> real_name if something

--

d(
	->
		print "hello world"
	10
)



d(
	1,2,3
	4
	5
	6

	if something
		print "okay"
		10

	10,20
)


f(
	
	)(
	
	)(
		what
	)(->
		print "srue"
	123)

--

x = (a,
	b) ->
	 print "what"


y = (a="hi",
	b=23) ->
		print "what"

z = (
	a="hi",
	b=23) ->
		print "what"


j = (f,g,m,
	a="hi",
	b=23
) ->
		print "what"


y = (a="hi",
	b=23,
	...) ->
		print "what"


y = (a="hi",
	b=23,
	...
) ->
		print "what"

--

args = (a
	b) ->
		print "what"


args = (a="hi"
	b=23) ->
		print "what"

args = (
	a="hi"
	b=23) ->
		print "what"


args = (f,g,m
	a="hi"
	b=23
) ->
		print "what"


@ = (n)->
	return 1 if n == 0
	n * @(n-1)

do
	items.every (item) ->
		if item.field
			value = item.field.get "abc"
			if value
				switch value\get!
					when 123
						return false
					when 456
						handle item
		true

	items.every (item): true ->
		if item.field
			value = item.field.get "abc"
			if value
				switch value\get!
					when 123
						return false
					when 456
						-- prevent implicit return for next line
						handle item

	HttpServer\post "/login", (req): success: false ->
		switch req when {:name, :pwd}
			if name ~= ""
				if user := DB\queryUser name, pwd
					if user.status == "available"
						return success: true

	check = (num) -> return num
	-- func without implicit return
	func = (): -> check 123
	print func! -- get nil

do
	f = ({:a, :b, :c}) -> print a, b, c
	f = (:a, :b, :c) -> print a, b, c
	g = (x, :y) -> print x, y
	i = ({a: ax = 0, b: by = 0}) -> print ax, by
	j = (name, {id: uid = "n/a", :role = "guest"}) -> print name, uid, role
	m = ({user: {:name, :age}, meta: {:ver = 1}}) -> print name, age, ver
	m1 = ({user: {:name, :age}, :meta = {}}) -> print name, age, meta and meta.ver or "nil"
	new = ({:name = "anon", :age = 0}) =>
		@name = name
		@age  = age
	set = ({:name = @name, :age = @age}) =>
		@name = name
		@age = age
	logKV = ({:k, :v}, ...) ->
		print "kv:", k, v
		print "rest count:", select "#", ...
	macro gen = (fname) -> |
	  #{fname} = ({:a, :b = 0}) -> print a, b
	$gen foo
	t1 = (:a, x) -> print a, x
	t2 = (:a) -> print a
	w = (
		id
		{:x = 0, :y = 0}
		:flag
	) ->
		print id, x, y, flag
	g1 = ({:a, a: ax}) -> print a, ax
	g4 = ({:a, :b, ...rest}) -> print a, b

nil