bonobo-lang / bonobo

Strongly-typed, safe, opinionated systems language that compiles to C.
https://bonobo-lang.github.io
Apache License 2.0
14 stars 1 forks source link

Arrays #39

Open thosakwe opened 6 years ago

thosakwe commented 6 years ago
f myArray : Int[] => [2, 3, 4]

f makeArray: (Int[], Int) {
  v arr := [1, 2], otherArr = [Int:255]
  ret otherArr, 255
}

f replaceFirst (array: Int[], n: Int): Void {
  array[0] = n
}
thosakwe commented 6 years ago

Note: Arrays are primitives, and not generic.

thosakwe commented 6 years ago

An array literal could also just set notation. This might make parsing logic a little more difficult, but it's still doable:

fn intArray: Int[] => {2, 3, 4}

fn spreadArray(a: Int[]) => {...a, 5, 6}
thosakwe commented 6 years ago

The problem with that is, how would you declare an array of known size?

Currently: var otherArr = [Int:255].

However, this conflicts with set notation {}.

{Int: 255} is also an object literal.

thosakwe commented 6 years ago

One option is reserving an Array keyword?

var arr = Array {Int:255}

Not sure how attractive that is.

Array<Int:255> is also a bit odd.

In C++, you can say new int[255].

In Bonobo?

Maybe new Int[255].

Not very consistent with {}.

Array Int[255]?

thosakwe commented 6 years ago

Our current consensus:

type FiveInts = Int[5]

Arrays are technically anonymous (though the analyzer can easily compare them), and have a fixed size, known both to the user and the compiler. They are not generic.

Collections, though, would be class-based, and generic.