SOMns icon indicating copy to clipboard operation
SOMns copied to clipboard

Add support for literal arrays

Open smarr opened this issue 8 years ago • 4 comments

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.

smarr avatar Jan 05 '17 17:01 smarr

How do you currently define a value array? Can you do something like {2. 4. 5} asValueArray?

fniephaus avatar Jan 07 '17 13:01 fniephaus

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.

smarr avatar Jan 09 '17 00:01 smarr

Status update: this task is worked on in #100

smarr avatar Jan 27 '17 14:01 smarr

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}

smarr avatar Jul 24 '17 07:07 smarr