Hi Gilad:
Thanks for the swift answer.
> On 28 Jan 2017, at 18:51, Gilad Bracha <
gbr...@gmail.com> wrote:
>
> Literal arrays are one of the few the Smalltalk expression language which is broken. They are at once too restrictive (they can only contain literals)
Ok, let’s start with literals in general. I suppose, I try to see literals in a way that allows them to be treated uniformly across the different kinds of literals.
We got numeric, boolean, nil, character, string, symbol, tuple, closure, and object literals (I haven’t really looked into pattern literals).
The only form to treat them uniformly for me seems to look at them as syntactic sugar for instantiating new objects with the ‘value’ encoded by the literal expression.
Taking Object literals, I assume it is natural to assume that it can have mutable slots. So, I would like to look at literals in Newspeak as rather different from literals in Smalltalk. The problem with Smalltalk is that they don’t have the notion to be expressions that generate new objects consistently. I suppose that’s mostly an unfortunate ‘optimization’ and only blocks retain that notion.
However, for Newspeak, I’d argue it is not an issue. Well, at least for SOMns it is not an issue to take that stance. Specifically, numeric, boolean, nil, character, string, and symbol literals all generate values, which don’t have any identity. So, arguing that they are fresh objects doesn’t really make a difference for them.
It’s not observable. For closures and objects, I suppose it is natural to see them as generator expressions that create a new object every time. And, both are somewhat mutable kinds objects.
From that, I’d argue that arrays should also be seen as freshly generated objects, which makes modifying them at least in my mind as natural as objects or closures.
> and not restrictive enough (the set of objects they contain can change). I've encountered (albeit rarely) code that changed literals after the fact. This was most egregious with literal strings (Squeak seems to prohibit this, but I remember systems that did not), but arrays as well.
Squeak and Pharo also have the `{Object new. Object new. #d. 3}` style arrays. They conform to the generator expression notion. So, you get every time a new mutable array.
And that’s what I was thinking of.
Now to the aspect of them being immutable.
I looked through all the SOMns code I got, which is some 36500 lines, mostly tests and benchmarks.
I didn’t see anything where I would yearn for literal arrays that are mutable. With the exception of test cases perhaps. Some of my language tests could benefit from that.
So, let’s say, I have neither a strong nor particularly informed opinion on shallow immutability.
I don’t have to notion of tuple in SOMns, but I suppose, that would be a minimal addition.
However, considering your point below:
> Nor does it preclude one from filling the tuple with deeply immutable values, in which case the implementation can determine quite easily that it is deeply immutable and mark it as such when the tuple is constructed (or lazily, or at a later time).
I disagree with the notion of implicit value semantics. I’d call that magic. And, when dealing with actor code, I would argue that it makes code brittle and error prone.
The issue is that when you construct objects/tuples just right, you get a value. If you pass it on to another actor, you can work directly with it. However, if one of your code path should return a mutable object somewhere along the way, everything gets tainted, and suddenly you code doesn’t work anymore, because you got an unexpected far reference in the other actor.
This is one of the reasons why in SOMns there is a strict distinction between objects and values. Objects are never implicitly promoted to values. Neither should tuples or for what its worth arrays be promoted.
Which means in effect, I would also want deeply immutable literal tuples/arrays.
[Tangent: Value objects check all their parameters on construction and if one isn’t a value, we get a NotAValue exception. However, there is a loophole to get a half-initialize Value object that will behave like a value but isn’t: you can escape it from the initializer expressions, I guess, perhaps by setting it on a slot of one of the parameters. I haven’t thought of a way to avoid that yet…]
> I'd urge you not to create semantic differences between the implementations. I’d like to try and harmonize the syntax of SOMns with the specification (and the other implementations) instead.
Yeah, I do try to stick as close to the spec as possible.
Sorry for not being more concise. Hope at least some of this makes sense.
Best regards
Stefan