[SPEC]: Vector Semantics? - #106
Conversation
|
I'm sorry, but I don't understand what your diagram is trying to say. In general, vectors are pretty close to interchangeable with 1D arrays, but vectors of vectors are completely different than 2D arrays. For most math ops, vectors and arrays are compatible, I think. For parameters, slices of vectors can be passed as array arguments, but arrays cannot be passed as vector arguments. vectors should be usable as iterators wherever arrays can be used as iterators. Like other languages, if you mutate the vector/array inside the loop, you can make bad things happen. We do not need to protect users from themselves. I suppose a good compiler would warn about yuckiness. It might also be fun to give some examples of programs stomping themselves. Functions must be pure, so they should be able to take const vectors. I would think changing the size is a side effect, unless the vectors are passed by deep copy. The compilers can either check that a vector is not modified, or pass by deep copy and let function do what it wants. Which do you think is better? |
|
BTW, I cannot find anything anywhere that uses the term elaboration as you do. The C99 spec seems to call them "variable length arrays", and Wikipedia indicates that VLAs are in 10 different languages, including Ada. I have to admit I do not understand where this is coming from. Can you show me the email trail of confused students who couldn't comprehend the array sizing semantics of Gazprea? |
|
All that said, I think your writing is beautiful, and explains everything wonderfully. If you rewrite the rest of the spec to match this level of clarity it will be amazing :-) |
I am not entirely sure I understand the current reading of vectors and would like to clarify it. I have a type lattice proposed that looks as follows:
Does this align with what you are going for? Are arrays and vectors able to be used interchangably? Can a vector be used as an iterator? If so what happens if the vector is mutated inside the iterator scope? Do we need to COW it?
Procedures returning vectors? Procedures taking vectors as arguments makes sense but can functions take vectors as arguments?