<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body dir="auto">
<div dir="ltr"></div>
<div dir="ltr">For completeness, I would like to point out a similarity between the reconstruction block of a wither expression and the compact constructor of a record. Both have a set of synthetic mutable locals, corresponding to the record components, and
operate by mutating those locals. The difference is how the locals get their values (parameters, or getters) and what they do with them (chain to a constructor, or invoke a constructor). </div>
<div dir="ltr"><br>
<blockquote type="cite">On Nov 30, 2024, at 9:42 AM, Aaryn Tonita <atonita@proton.me> wrote:<br>
<br>
</blockquote>
</div>
<blockquote type="cite">
<div dir="ltr">
<div style="font-family: Arial, sans-serif; font-size: 14px;">I am very excited about withers, immutable objects are really inconvenient without such utility methods. I recently saw the distinction in the thread on '<span>"With" for records and the default
constructor</span>' between withers and nominal constructors. I too have wished for such nominal constructors, and took notice that it isn't a priority. Fair enough.<br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;">But that got me thinking about why I wanted it and how else it could be done in user land and I recalled that JEP 468 makes an excellent point for the flexibility of use site creation of new values
to avoid bloat on the declaring class. This explanation feels very much like the power of procedural macros which can generate the obvious boilerplate binding at the use site. If you were in fact adding procedural macro support (through something roughly equivalent
to annotation processors) then the community could fill in the gaps for nominal creation and many other features. In either case withers seem to be work that the compiler has to perform at the use site and that can either be built in or plugged in.<br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;">In another thread you pointed out that you see this as a regularization feature and not a cool new feature which procedural macros certainly would be. However, the current syntax seems like it would
be hard to retro fit to a procedural macro later on (if you would decide that later) while a different syntax might allow you to retrofit the work the compiler must do as a library procedural macro.<br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;">I figure you must have considered procedural macros at some point. Certainly java has some code generation functionality as is but to me it does feel quite different than procedural macros (or the
higher order function capabilities of python annotations) feel in other languages. Annotation processors feel like a genuinely separate build step. In fact, powerful string templating could be delivered with such a feature where the procedural could read
<code>format!("{foo}")</code> and close over the scoped variable foo or fail to compile when it is not in scope. So something like
<code>with!(point, x=localX, y=localY)</code> could yield this and more like <code>
with!(point3D, point2D, z=localZ)</code> for a nominal construction?.<br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;">That syntax definitely feels very un-java though.<br>
</div>
<div class="protonmail_signature_block protonmail_signature_block-empty" style="font-family: Arial, sans-serif; font-size: 14px;">
<div class="protonmail_signature_block-user protonmail_signature_block-empty"></div>
<div class="protonmail_signature_block-proton protonmail_signature_block-empty"></div>
</div>
</div>
</blockquote>
</body>
</html>