Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays #39

Open
thosakwe opened this issue Apr 19, 2018 · 5 comments
Open

Arrays #39

thosakwe opened this issue Apr 19, 2018 · 5 comments

Comments

@thosakwe
Copy link
Contributor

thosakwe commented Apr 19, 2018

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
Copy link
Contributor Author

Note: Arrays are primitives, and not generic.

@thosakwe
Copy link
Contributor Author

thosakwe commented Apr 22, 2018

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
Copy link
Contributor Author

thosakwe commented Apr 22, 2018

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
Copy link
Contributor Author

thosakwe commented Apr 22, 2018

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant