Where does this array come from ?
Remi Forax
forax at univ-mlv.fr
Tue Apr 7 17:53:11 UTC 2020
Even without Map, in Caml/OCaml, you have positional matching and also record component name matching.
Translated in Java-ish:
record Point(int x, int) { }
switch(shape) {
case Point(int x, int y) -> ... // positional based
case Point { int myX = x, int myY = y } -> // record component name based
...
}
Using component names has the advantage that adding record component is a backward compatible change.
Rémi
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Stephen Colebourne" <scolebourne at joda.org>, "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Lundi 6 Avril 2020 16:03:11
> Objet: Re: Where does this array come from ?
> I'm fine with { ... } too; if we ever get map literals / patterns, they
> are far more likely to use { ... } than [ ... ].
>
> On 4/6/2020 9:45 AM, Stephen Colebourne wrote:
>> FWIW, a colleague has previously argued that the toString of a bean
>> should be JSON. At a company he worked at, all their beans were JSON
>> and it apparently allowed them to build tooling on top of the
>> toString. I'm not sure I'm convinced about JSON, but I do think a
>> record is closer to a map than a list. And yes, Joda-Beans uses {} not
>> [].
>> Stephen
>>
>>
>> On Mon, 6 Apr 2020 at 14:01, Brian Goetz <brian.goetz at oracle.com> wrote:
>>> Perhaps we should rotate the punctuation every version just to discourage
>>> parsing :)
>>>
>>>> On Apr 6, 2020, at 7:34 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>>>>
>>>> I've was debugging a code yesterday that was printing
>>>> Empty[]
>>>>
>>>> After some head scratching, trying to find an array of Empty, i found that it
>>>> was just an empty record
>>>> record Empty() { }
>>>>
>>>> This is another clue that using square brackets for toString() is a bad idea !
>>>>
>>>> regards,
> >>> Rémi
More information about the amber-dev
mailing list