File: moonbit.mbt

package info (click to toggle)
cloc 2.06-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,064 kB
  • sloc: perl: 30,146; cpp: 1,219; python: 623; ansic: 334; asm: 267; makefile: 244; sh: 186; sql: 144; java: 136; ruby: 111; cs: 104; pascal: 52; lisp: 50; haskell: 35; f90: 35; cobol: 35; objc: 25; php: 22; javascript: 15; fortran: 9; ml: 8; xml: 7; tcl: 2
file content (54 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download | duplicates (2)
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
///|
///without spaces
/// 返回一个新数组,其中元素被反转。
///
/// # 示例
///
/// ```
/// reverse([1,2,3,4]) |> println()
/// ```
fn reverse[T](xs : Array[T]) -> Array[T] {
  Array::rev(xs)
}

test {
  assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) // pass
  assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) //pass
  let _ = "https://github.com"
}

fn main {
  let greeting =
    #|
    #|     (\(\
    #|     ( -.-)
    #|     o_(")(")
    #|     __  __     ____         __  ___                  ____  _ __
    #|    / / / /__  / / /___     /  |/  /___  ____  ____  / __ )(_) /_
    #|   / /_/ / _ \/ / / __ \   / /|_/ / __ \/ __ \/ __ \/ __  / / __/
    #|  / __  /  __/ / / /_/ /  / /  / / /_/ / /_/ / / / / /_/ / / /_
    #| /_/ /_/\___/_/_/\____/  /_/  /_/\____/\____/_/ /_/_____/_/\__/
    #|
  println(greeting)

    // Define two array of Int.
  let arr1 : Array[Int] = [1, 2, 3, 4, 5]

  // Let compiler infer the type.
  let arr2 = [6, 7, 8, 9, 10]

  // Get the length of the array.
  println(arr1.length())

  // Access the element of the array.
  println(arr1[1]) 

  // We change the elements inside the array. 
  // The binding of arr1 is immutable, it still points to the same array.
  // The internal mutability of the array is defined by the standard library and 
  // is not affected by the binding.
  arr1.push(6) 
  arr1[1] = 10
  println("push and change element:")
  println(arr1)
}