<div dir="auto">Ah, great, I like this! Thanks!</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 21 Jun 2023 at 16:08 Juan Vuletich <<a href="mailto:juan@cuis.st">juan@cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Hi Luciano,<br>
<br>
The style I learn from Squeak long time ago is to receive a block and <br>
evaluate it with the values that would be answered. In your example it <br>
would be<br>
<br>
a xgcd: b into: [ :g :s :t | ... ]<br>
<br>
It is very similar to what you propose, but it avoids creating an extra <br>
array. See, for example, senders of <br>
#barycentricCoordinatesInTriangle:with:with:into:ifDegenerate: and <br>
#nextUtf8BytesAndCodePointInto:into:<br>
<br>
This style doesn't require any additions to the image and is expressive <br>
enough in my opinion.<br>
<br>
Cheers,<br>
<br>
On 6/21/2023 10:13 AM, Luciano Notarfrancesco via Cuis-dev wrote:<br>
> Smalltalk doesn’t have a convention for methods returning multiple <br>
> values, and I’m not aware of any implementation.<br>
> An example of such thing is the extended gcd: ‘a xgcd: b’ returns g, <br>
> s, t where g is the gcd, and as + bt = g. Writing methods that return <br>
> multiple values is easy with the curly brackets syntax, <br>
> Integer>>#xgcd: ends with something like<br>
>     ^ {g. s. t}<br>
> But using sending messages that return multiple values is kind of <br>
> annoying, I end up doing something like:<br>
>     xgcd := a xgcd: b.<br>
>     g := xgcd at: 1.<br>
>     s := xgcd at: 2.<br>
>     t := xgcd at: 3<br>
> Some years ago I thought about using blocks for this, but I never <br>
> tried it. Today I just did a little experiment implementing anArray | <br>
> aBlock as ‘^ aBlock valueWithPossibleArgs: self’ and I can do:<br>
>     (a xgcd: b) | [:g :s :t| … ]<br>
><br>
> This is seems quite nice already, I guess I’ll start using it and see <br>
> how it feels. But the point of this mail is not to show a solution, <br>
> but to ask if anyone have thought about this or if they know any nicer <br>
> solutions. Any ideas?<br>
<br>
<br>
-- <br>
Juan Vuletich<br>
<a href="http://cuis.st" rel="noreferrer" target="_blank">cuis.st</a><br>
<a href="http://github.com/jvuletich" rel="noreferrer" target="_blank">github.com/jvuletich</a><br>
<a href="http://researchgate.net/profile/Juan-Vuletich" rel="noreferrer" target="_blank">researchgate.net/profile/Juan-Vuletich</a><br>
<a href="http://independent.academia.edu/JuanVuletich" rel="noreferrer" target="_blank">independent.academia.edu/JuanVuletich</a><br>
<a href="http://patents.justia.com/inventor/juan-manuel-vuletich" rel="noreferrer" target="_blank">patents.justia.com/inventor/juan-manuel-vuletich</a><br>
<a href="http://linkedin.com/in/juan-vuletich-75611b3" rel="noreferrer" target="_blank">linkedin.com/in/juan-vuletich-75611b3</a><br>
<a href="http://twitter.com/JuanVuletich" rel="noreferrer" target="_blank">twitter.com/JuanVuletich</a><br>
<br>
</blockquote></div></div>