Debian Codegraph @

tests/inputs/moonbit.mbt

raw
1 ///|
2 ///without spaces
3 /// 返回一个新数组,其中元素被反转。
4 ///
5 /// # 示例
6 ///
7 /// ```
8 /// reverse([1,2,3,4]) |> println()
9 /// ```
10 fn reverse[T](xs : Array[T]) -> Array[T] {
11 Array::rev(xs)
12 }
13
14 test {
15 assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) // pass
16 assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) //pass
17 let _ = "https://github.com"
18 }
19
20 fn main {
21 let greeting =
22 #|
23 #| (\(\
24 #| ( -.-)
25 #| o_(")(")
26 #| __ __ ____ __ ___ ____ _ __
27 #| / / / /__ / / /___ / |/ /___ ____ ____ / __ )(_) /_
28 #| / /_/ / _ \/ / / __ \ / /|_/ / __ \/ __ \/ __ \/ __ / / __/
29 #| / __ / __/ / / /_/ / / / / / /_/ / /_/ / / / / /_/ / / /_
30 #| /_/ /_/\___/_/_/\____/ /_/ /_/\____/\____/_/ /_/_____/_/\__/
31 #|
32 println(greeting)
33
34 // Define two array of Int.
35 let arr1 : Array[Int] = [1, 2, 3, 4, 5]
36
37 // Let compiler infer the type.
38 let arr2 = [6, 7, 8, 9, 10]
39
40 // Get the length of the array.
41 println(arr1.length())
42
43 // Access the element of the array.
44 println(arr1[1])
45
46 // We change the elements inside the array.
47 // The binding of arr1 is immutable, it still points to the same array.
48 // The internal mutability of the array is defined by the standard library and
49 // is not affected by the binding.
50 arr1.push(6)
51 arr1[1] = 10
52 println("push and change element:")
53 println(arr1)
54 }