1// Copyright 2025 International Digital Economy Academy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15///|
16fn moonbit_get_cli_args() -> 
type FixedArray[A]
FixedArray
[
Bytes
Bytes
] = "$moonbit.get_cli_args"
17 18///| 19let
FixedArray[String]
_args
:
type FixedArray[A]
FixedArray
[
String
String
] = {
20 let
FixedArray[Bytes]
argv
=
() -> FixedArray[Bytes]
moonbit_get_cli_args
()
21
type FixedArray[A]
FixedArray
::
(length : Int, value : (Int) -> String) -> FixedArray[String]

Creates a new fixed-size array of the specified length, where each element is initialized using a function that maps indices to values.

Parameters:

  • length : The length of the array to create. If length is less than or equal to 0, returns an empty array.
  • initializer : A function that takes an index (from 0 to length - 1) and returns a value of type T for that position.

Returns a new fixed array containing the values produced by applying the initializer function to each index.

Example:

  let arr = FixedArray::makei(3, fn(i) { i * 2 })
  inspect(arr, content="[0, 2, 4]")
makei
(
FixedArray[Bytes]
argv
.
(self : FixedArray[Bytes]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
(), fn(
Int
i
) {
22
(encoding~ : @encoding.Encoding, input : @bytes.View) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
,
FixedArray[Bytes]
argv
(FixedArray[Bytes], Int) -> Bytes

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
[
i])
23 }) 24} 25 26///| 27#deprecated("Use `args` instead") 28pub fn
() -> Array[Bytes]
argv
() ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
Bytes
Bytes
] {
29 let
FixedArray[Bytes]
argv
=
() -> FixedArray[Bytes]
moonbit_get_cli_args
()
30
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
::
(Int, (Int) -> Bytes) -> Array[Bytes]

Creates a new array of the specified length, where each element is initialized using an index-based initialization function.

Parameters:

  • length : The length of the new array. If length is less than or equal to 0, returns an empty array.
  • initializer : A function that takes an index (starting from 0) and returns a value of type T. This function is called for each index to initialize the corresponding element.

Returns a new array of type Array[T] with the specified length, where each element is initialized using the provided function.

Example:

  let arr = Array::makei(3, fn(i) { i * 2 })
  inspect(arr, content="[0, 2, 4]")
makei
(
FixedArray[Bytes]
argv
.
(self : FixedArray[Bytes]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
(), fn(
Int
i
) {
FixedArray[Bytes]
argv
(FixedArray[Bytes], Int) -> Bytes

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
[
i] })
31} 32 33///| 34/// Returns a _copy_ of command-line arguments passed to the program. 35/// 36/// The arguments are copied to prevent accidental/intentional modification to 37/// the original command-line arguments. 38/// 39/// Example: 40/// 41/// ```moonbit 42/// println(@uv.args()) 43/// ``` 44pub fn
() -> Array[String]

Returns a copy of command-line arguments passed to the program.

The arguments are copied to prevent accidental/intentional modification to the original command-line arguments.

Example:

println(@uv.args())
args
() ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
String
String
] {
45
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
::
(FixedArray[String]) -> Array[String]

Creates a new dynamic array from a fixed-size array.

Parameters:

  • arr : The fixed-size array to convert. The elements of this array will be copied to the new array.

Returns a new dynamic array containing all elements from the input fixed-size array.

Example:

  let fixed = FixedArray::make(3, 42)
  let dynamic = Array::from_fixed_array(fixed)
  inspect(dynamic, content="[42, 42, 42]")
from_fixed_array
(
FixedArray[String]
_args
)
46} 47