Reconstruction expression with explicit deconstuctor (REWED)

David Alayachew davidalayachew at gmail.com
Sat Sep 23 13:40:28 UTC 2023


Hello Nyehamene,

Thank you for your response!

I am in FULL SUPPORT of this feature. It feels like it falls right in-line
with how lambdas currently work. Furthermore, it takes full advantage of
the pattern-matching options available to us now, and even in the future.
This sounds beautiful to me.

Thank you for your time and help!
David Alayachew

On Sat, Sep 23, 2023 at 6:01 AM Harrison Chikwe <nhcdeveloper at gmail.com>
wrote:

> Hi,
>
> I think that it is very useful to have when working with immutable objects.
>
> For the purposes of this mail, let's call the design described in the
> ambro-doc[1]:
> reconstruction expression with implicit deconstructor (aka REWID).
>
> Has it been considered to make the deconstructor pattern explicit in the
> reconstruction
> expression (aka REWED)?
> Doing so may remove the requirement to make names more significant in the
> language.
>
> For example, given the following:
>
> Point p = ...;
> Point pp = p with(int x, int y) { x += 2; y = 0; }
>
> We can interpret the reconstruction expression above as:
>
> . Find a deconstructor and constructor pair that has a signature that
> matches (int, int)
> . Deconstruct the target with the deconstructor
> . Execute the block on RHS
> . Invoke the constructor with the result.
>
> If we split the reconstruction expression into three steps:
>
> 1. Extraction
> 2. Transformation
> 3. Construction
>
> In REWID users are required only to do step 2 (transformation) and the
> system handles 1 and 3. Whereas in REWED users are required to do step 1
> and 2
> and the system handles just step 3.
>
> # Other forms of REWED
>
> 1. Explicit Named deconstructor pattern
>
>    Point pp = p with Point(int x, int y) {...}
>
> 2. Explicit Var deconstructor pattern
>
>    Point pp = p with var(int x, int y) {...}
>
> 3. Explicit Unnamed deconstructor pattern
>
>    Point pp = p with(int x, int y) {...}
>
>
> We can extend form 1 to include factory pattern:
>
>    Point pp = p with Point.factory(int x, int y) {...}
>
>
> # Advantages
>
> 1. No need to make names significant.
> 2. Can be combined with other patterns (e.g. unnamed pattern, var pattern)
>
>    Point pp = p with(int x, _) { x = 0; }
>
>
> Nyehamene.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20230923/ec313226/attachment-0001.htm>


More information about the amber-spec-observers mailing list