<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>Hi Levente,</p>
<p><br>
</p>
<p>IMHO a DSL is very much about syntactic sugar. If we obviate it, we impede the development of richer and higher-level language concepts that abstract from repetitive and uninteresting basics such as the temporary variable in your example. Just my two cents.
:-)</p>
<p><br>
</p>
<p>Best,</p>
<p>Christoph</p>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves@caesar.elte.hu><br>
<b>Gesendet:</b> Dienstag, 30. März 2021 22:21:00<br>
<b>An:</b> ma.chris.m@gmail.com; The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] Extending the functionality of caseOf: (was: #identityCaseOf:)</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi Chris,<br>
<br>
On Sun, 28 Mar 2021, Chris Muller wrote:<br>
<br>
> > For example, passing the object to the condition block (or even the result<br>
> > block) could be useful:<br>
> ><br>
> > self someComplexExpression caseOf: {<br>
> > [ 1 ] -> [ self success ]<br>
> > [ :value | value odd ] -> [ :value | self processEvenValue: value -<br>
> > 1 ].<br>
> > [ :value | true "it's even ] -> [ :value | self processEvenValue ] } <br>
><br>
> ><br>
> > There are two new things in the example:<br>
> > - the value of self someComplexExpression is optionally passed to the<br>
> > blocks. Yes, that could be done by creating a temporary variable.<br>
> <br>
> <br>
> Here's the version using a temporary and existing API (with an added identity-check).<br>
> <br>
> result := self someComplexExpression.<br>
> true caseOf:<br>
> { [result=1] -> [self success].<br>
> [result odd] -> [self processEvenValue: result-1].<br>
> [ result == identityValue ] -> [self processSomethingElse ].<br>
> [true] -> [self processEvenValue] }<br>
> <br>
> "true caseOf:" is my sneaky way to improve its flexibility. The suggested expansion of the API seems too dilute, not enough bang.<br>
<br>
Yes, it does the job, but it's a bit more verbose and probably less <br>
efficient: you have to declare the variable yourself, and you have to <br>
write result=1 instead of just 1.<br>
<br>
> <br>
> The<br>
> > compiler could do exactly that behind the scenes.<br>
> > - when the value is passed to the matcher block, possibilities are greatly<br>
> > extended.<br>
> <br>
> <br>
> The evaluation is done before any of the caseOf tests, so is it really extended with more expressive power? Or just a different syntax that moves the variable declaration from a temporary to the block arg?<br>
<br>
It's just syntactic sugar. The optimized evaluation would just reuse the <br>
existing temporary instead of creating a new one all the time.<br>
The default implementation would be<br>
<br>
Object >> caseOf: aBlockAssociationCollection otherwise: aBlock<br>
<br>
aBlockAssociationCollection associationsDo:<br>
[:assoc | (assoc key numArgs = 0<br>
ifTrue: [ assoc key value = self ]<br>
ifFalse: [ assoc key value: self ]) ifTrue: [^assoc value cull: self]].<br>
^ aBlock cull: self<br>
<br>
<br>
Levente<br>
<br>
> <br>
> For example, it could even reproduce #identityCaseOf:<br>
> ><br>
> > foo caseOf: {<br>
> > [ :o | o == #foo ] -> [ self foo ].<br>
> > [ :o | o == #bar ] -> [ self bar ] }<br>
> ><br>
> > The same thing could be done with the otherwise block too:<br>
> ><br>
> > self foo<br>
> > caseOf: { ... }<br>
> > otherwise: [ :value | value ]<br>
> ><br>
> ><br>
> > Levente<br>
> ><br>
> <br>
> <br>
> <br>
></div>
</span></font>
</body>
</html>