moonbitlang / core

MoonBit's Core library
https://moonbitlang.com/
Apache License 2.0
584 stars 72 forks source link

about arr.reverse return value && doc in CONTRIBUTING.md Usage. #510

Closed npmstudy closed 1 month ago

npmstudy commented 4 months ago

image

the code not work

$ moon new hello
$ cd hello
$ echo """fn main {
  println([1, 2, 3].reverse())
}""" > main/main.mbt
$ moon run main
# Output: [3, 2, 1]

the rignt way

$ moon new hello
$ cd hello
$ echo """fn main {
  let v = [1, 2, 3]
  v.reverse()
  println(v)
}""" > main/main.mbt
$ moon run main
# Output: [3, 2, 1]
npmstudy commented 4 months ago
reverse[T](Self[T]) -> Unit

maybe it should be return array like js https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse

bobzhang commented 4 months ago

@npmstudy how about provding reverse and revrese_in_place?