aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/id-id/doc/functions/function-literals.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs/id-id/doc/functions/function-literals.md')
-rw-r--r--doc/docs/id-id/doc/functions/function-literals.md27
1 files changed, 25 insertions, 2 deletions
diff --git a/doc/docs/id-id/doc/functions/function-literals.md b/doc/docs/id-id/doc/functions/function-literals.md
index 589a26d..67ae158 100644
--- a/doc/docs/id-id/doc/functions/function-literals.md
+++ b/doc/docs/id-id/doc/functions/function-literals.md
@@ -6,6 +6,7 @@ Semua fungsi dibuat menggunakan ekspresi fungsi. Fungsi sederhana ditandai denga
6my_function = -> 6my_function = ->
7my_function() -- memanggil fungsi kosong 7my_function() -- memanggil fungsi kosong
8``` 8```
9
9<YueDisplay> 10<YueDisplay>
10 11
11```yue 12```yue
@@ -24,6 +25,7 @@ func_b = ->
24 value = 100 25 value = 100
25 print "The value:", value 26 print "The value:", value
26``` 27```
28
27<YueDisplay> 29<YueDisplay>
28 30
29```yue 31```yue
@@ -42,6 +44,7 @@ Jika fungsi tidak memiliki argumen, ia dapat dipanggil menggunakan operator `!`,
42func_a! 44func_a!
43func_b() 45func_b()
44``` 46```
47
45<YueDisplay> 48<YueDisplay>
46 49
47```yue 50```yue
@@ -56,6 +59,7 @@ Fungsi dengan argumen dapat dibuat dengan menaruh daftar nama argumen dalam tand
56```yuescript 59```yuescript
57sum = (x, y) -> print "sum", x + y 60sum = (x, y) -> print "sum", x + y
58``` 61```
62
59<YueDisplay> 63<YueDisplay>
60 64
61```yue 65```yue
@@ -72,6 +76,7 @@ print sum 10, 20
72 76
73a b c "a", "b", "c" 77a b c "a", "b", "c"
74``` 78```
79
75<YueDisplay> 80<YueDisplay>
76 81
77```yue 82```yue
@@ -88,6 +93,7 @@ Untuk menghindari ambiguitas saat memanggil fungsi, tanda kurung juga bisa digun
88```yuescript 93```yuescript
89print "x:", sum(10, 20), "y:", sum(30, 40) 94print "x:", sum(10, 20), "y:", sum(30, 40)
90``` 95```
96
91<YueDisplay> 97<YueDisplay>
92 98
93```yue 99```yue
@@ -104,6 +110,7 @@ Fungsi akan memaksa pernyataan terakhir di badannya menjadi pernyataan return, i
104sum = (x, y) -> x + y 110sum = (x, y) -> x + y
105print "The sum is ", sum 10, 20 111print "The sum is ", sum 10, 20
106``` 112```
113
107<YueDisplay> 114<YueDisplay>
108 115
109```yue 116```yue
@@ -118,6 +125,7 @@ Dan jika Anda perlu return secara eksplisit, Anda bisa menggunakan kata kunci `r
118```yuescript 125```yuescript
119sum = (x, y) -> return x + y 126sum = (x, y) -> return x + y
120``` 127```
128
121<YueDisplay> 129<YueDisplay>
122 130
123```yue 131```yue
@@ -132,6 +140,7 @@ Seperti di Lua, fungsi dapat mengembalikan beberapa nilai. Pernyataan terakhir h
132mystery = (x, y) -> x + y, x - y 140mystery = (x, y) -> x + y, x - y
133a, b = mystery 10, 20 141a, b = mystery 10, 20
134``` 142```
143
135<YueDisplay> 144<YueDisplay>
136 145
137```yue 146```yue
@@ -148,6 +157,7 @@ Karena sudah menjadi idiom di Lua untuk mengirim objek sebagai argumen pertama s
148```yuescript 157```yuescript
149func = (num) => @value + num 158func = (num) => @value + num
150``` 159```
160
151<YueDisplay> 161<YueDisplay>
152 162
153```yue 163```yue
@@ -165,6 +175,7 @@ my_function = (name = "something", height = 100) ->
165 print "Hello I am", name 175 print "Hello I am", name
166 print "My height is", height 176 print "My height is", height
167``` 177```
178
168<YueDisplay> 179<YueDisplay>
169 180
170```yue 181```yue
@@ -181,6 +192,7 @@ Ekspresi nilai default argumen dievaluasi di dalam badan fungsi sesuai urutan de
181some_args = (x = 100, y = x + 1000) -> 192some_args = (x = 100, y = x + 1000) ->
182 print x + y 193 print x + y
183``` 194```
195
184<YueDisplay> 196<YueDisplay>
185 197
186```yue 198```yue
@@ -202,6 +214,7 @@ b = x-10
202c = x -y 214c = x -y
203d = x- z 215d = x- z
204``` 216```
217
205<YueDisplay> 218<YueDisplay>
206 219
207```yue 220```yue
@@ -223,6 +236,7 @@ Ketika ada spasi setelah variabel dan literal string, pemanggilan fungsi bertind
223x = func"hello" + 100 236x = func"hello" + 100
224y = func "hello" + 100 237y = func "hello" + 100
225``` 238```
239
226<YueDisplay> 240<YueDisplay>
227 241
228```yue 242```yue
@@ -247,6 +261,7 @@ cool_func 1, 2,
247 5, 6, 261 5, 6,
248 7, 8 262 7, 8
249``` 263```
264
250<YueDisplay> 265<YueDisplay>
251 266
252```yue 267```yue
@@ -269,6 +284,7 @@ my_func 5, 6, 7,
269 9, 1, 2, 284 9, 1, 2,
270 5, 4 285 5, 4
271``` 286```
287
272<YueDisplay> 288<YueDisplay>
273 289
274```yue 290```yue
@@ -289,6 +305,7 @@ x = [
289 8, 9, 10 305 8, 9, 10
290] 306]
291``` 307```
308
292<YueDisplay> 309<YueDisplay>
293 310
294```yue 311```yue
@@ -309,6 +326,7 @@ y = [ my_func 1, 2, 3,
309 5, 6, 7 326 5, 6, 7
310] 327]
311``` 328```
329
312<YueDisplay> 330<YueDisplay>
313 331
314```yue 332```yue
@@ -335,6 +353,7 @@ if func 1, 2, 3,
335 print "hello" 353 print "hello"
336 print "I am inside if" 354 print "I am inside if"
337``` 355```
356
338<YueDisplay> 357<YueDisplay>
339 358
340```yue 359```yue
@@ -357,9 +376,9 @@ if func 1, 2, 3,
357 376
358YueScript kini mendukung destrukturisasi parameter fungsi ketika argumen berupa objek. Dua bentuk destrukturisasi literal tabel tersedia: 377YueScript kini mendukung destrukturisasi parameter fungsi ketika argumen berupa objek. Dua bentuk destrukturisasi literal tabel tersedia:
359 378
360* **Literal berkurung kurawal/parameter objek**, memungkinkan nilai default opsional ketika field hilang (misalnya, `{:a, :b}`, `{a: a1 = 123}`). 379- **Literal berkurung kurawal/parameter objek**, memungkinkan nilai default opsional ketika field hilang (misalnya, `{:a, :b}`, `{a: a1 = 123}`).
361 380
362* **Sintaks tabel sederhana tanpa pembungkus**, dimulai dengan urutan key-value atau binding singkat dan berlanjut sampai ekspresi lain menghentikannya (misalnya, `:a, b: b1, :c`). Bentuk ini mengekstrak beberapa field dari objek yang sama. 381- **Sintaks tabel sederhana tanpa pembungkus**, dimulai dengan urutan key-value atau binding singkat dan berlanjut sampai ekspresi lain menghentikannya (misalnya, `:a, b: b1, :c`). Bentuk ini mengekstrak beberapa field dari objek yang sama.
363 382
364```yuescript 383```yuescript
365f1 = (:a, :b, :c) -> 384f1 = (:a, :b, :c) ->
@@ -373,6 +392,7 @@ f2 = ({a: a1 = 123, :b = 'abc'}, c = {}) ->
373arg1 = {a: 0} 392arg1 = {a: 0}
374f2 arg1, arg2 393f2 arg1, arg2
375``` 394```
395
376<YueDisplay> 396<YueDisplay>
377 397
378```yue 398```yue
@@ -402,6 +422,7 @@ findFirstEven = (list): nil ->
402 if sub % 2 == 0 422 if sub % 2 == 0
403 return sub 423 return sub
404``` 424```
425
405<YueDisplay> 426<YueDisplay>
406 427
407```yue 428```yue
@@ -426,6 +447,7 @@ findFirstEven = (list) ->
426 return sub 447 return sub
427 nil 448 nil
428``` 449```
450
429<YueDisplay> 451<YueDisplay>
430 452
431```yue 453```yue
@@ -467,6 +489,7 @@ process = (...args) ->
467 489
468process 1, nil, 3, nil, 5 490process 1, nil, 3, nil, 5
469``` 491```
492
470<YueDisplay> 493<YueDisplay>
471 494
472```yue 495```yue