Sunday, July 13, 2014

Yin Wang on mutable and immutable arrays

Wombat can easily accommodate Yin Wang's ideas on arrays: Design mistakes in Swift language’s array.

In Wombat a 1-dimensional Array is immutable and the same as a List (see footnote). To get a mutable Array of X you instead create an Array(Assignable(X)). Conceptually it is a fixed array of addresses in memory. And we can easily create an operator similar to the proposed [[1,2]]. It would create an Array(Assignable(Int)) with 2 entries initialized to 1 and 2 respectively. However the specific syntax is taken (being a one element Array whose element is [1,2]). But something similar like ≪1,2≫ is ok.

footnote: Traditionally a List was a singly linked list where you could efficiently prepend values, and an array was a contiguous block of memory. However the semantics can be identical (with differing efficiencies). Languages should be about semantics and not about implementation and efficiency. The programmer should mostly leave efficiency to the compiler, with the occasional pragma.

[update: just changed Mutable to Assignable]

No comments:

Post a Comment