<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Jim Laskey" <james.laskey@oracle.com><br><b>To: </b>"DWR" <davidwrogers2@gmail.com><br><b>Cc: </b>"amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Friday, March 31, 2023 1:53:40 PM<br><b>Subject: </b>Re: JEP430<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
The current design allows for you to ensure that the arguments are of a certain type at runtime. Compile time checks are not possible.
<div><br>
</div>
<div>
<div><font face="Consolas"><span style="font-style: normal;">import java.lang.StringTemplate.Processor;</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;"><br></span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">public class Main {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">    record Complex(double r, double i) {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        public String toString() {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">            return STR."[\{r} + \{i}i]";</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        }</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">     }</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;"><br></span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">    private static final Processor<String, IllegalArgumentException> DSL = st -> {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        for (Object value : st.values()) {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">            if (!(value instanceof Complex)) {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">                throw new IllegalArgumentException("Value is not Complex");</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">            }</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        }</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;"><br></span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        // ...</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;"><br></span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        return StringTemplate.interpolate(st.fragments(), st.values());</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">    };</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;"><br></span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">    public static void main(String... args) {</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        Complex x = new Complex(10.0, 3.33), y = new Complex(20.0, 6.67);</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        String result = DSL."\{x} + \{y}";</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        System.out.println(result);</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">        System.out.println("Done!");</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">    }</span></font></div>
<div><font face="Consolas"><span style="font-style: normal;">}</span></font></div>
</div>
<div><br>
</div>
<div>——————————————————————————</div>
<div><br>
</div>
<div>
<div>[10.0 + 3.33i] + [20.0 + 6.67i]</div>
<div>Done!</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>— Jim</div></blockquote><div><br></div><div>If the code has not changed too much since the last time I checked, in term of performance, you can improve the code a bit and do the runtime check only once per callsite.<br data-mce-bogus="1"></div><div>The StringTemplate implementation class is always the same per callsite and retain the type of the captured values.</div><div>Thus you can install an inlining cache on that class so the arguments types can be checked once per callsite.</div><div><br data-mce-bogus="1"></div><div>This is similar to the way VarH<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div><br>
</div>
<div><br>
</div>
<div><br>
<div>
<blockquote>
<div>On Mar 27, 2023, at 9:56 PM, DWR <davidwrogers2@gmail.com> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>Hi, I was wondering if there is a way to constrain the type of the<br>
embedded expressions? E.g. "for DSL Foo the embedded expressions<br>
should all be of some type of a sealed hierarchy of Node types".<br>
</div>
</div>
</blockquote>
</div>
<br>
</div><br></blockquote></div></div></body></html>