SOMns
SOMns copied to clipboard
Add support for literal arrays
I really miss the ability to simply note down a literal array.
As far as I can see, the spec only talks about arrays in very few places, and uses the {2. 4. 5} notation. That is a list of expressions, of which their return value defines the value of the corresponding array index.
So, {self foo. 4 + 3. a <-: hello: 'ww'} is perfectly legal, and might evaluate to {self. 7. a Promise}.
What's unclear is how we can have value arrays supported as well.
Perhaps one option would be to use the # sign as an indicator, and make #{2. 4. 5} a value array. That's somewhat in Smalltalk tradition of #(foo bar 42) evaluating to {#foo. #bar. 42}, except that Smalltalk doesn't have ValueArrays, and this seems merely a convenience to note down a list of symbols without too much syntactical noise. Not sure I really care for such symbol arrays.
How do you currently define a value array? Can you do something like {2. 4. 5} asValueArray?
There is no such helper in SOMns. There is only this: https://github.com/smarr/SOMns/blob/master/core-lib/Kernel.som#L572
So, it would be i := 0. ValueArray new: arr size withAll: [ i := i + 1. arr at: i ].
And a brief grep reveals that I don't even use ValueArrays currently. I added them for one of the Savina benchmarks, but, seems I never completed the implementation of that benchmark.
Status update: this task is worked on in #100
With #173 merged, we got array literals. However, I'll leave the issue here open, since I'd still love to have literal value arrays, which guarantee to be deeply immutable.
Should probably look like: #{#44. 55. MyValue new: 55}