<div dir="auto">Interesting, thanks for sharing!</div><div dir="auto">Actually I think it’s the same thing I did, my implementation calls BlockClosure>>#valueWithPossibleArgs: and takes only as many arguments as needed by the block but the array can be bigger than that (it should be named #valueWithPossibleArguments: tho, abbreviations are ugly).</div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 21 Jun 2023 at 15:37 Christian Haider via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.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)"><div lang="DE" link="#0563C1" vlink="#954F72" style="overflow-wrap: break-word;"><div class="m_-976565113171439616WordSection1"><p class="MsoNormal"><span lang="EN-CA">I added something similar to my Values package (VW and ports).<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA">The source is<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New"">SequenceableCollection>>asArgumentsIn: aBlock<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> "Evaluate aBlock with the receiver's elements as parameters.<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> aBlock takes its arguments from the receiver.<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> 'ok'<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> #(1 2 3) asArgumentsIn: [:a :b :c | a + b + c]<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> #(1 2 3) asArgumentsIn: [:a :b | a + b]<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> #(1 2 3) asArgumentsIn: [:a | a]<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> #(1 2 3) asArgumentsIn: [42]<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> 'not ok'<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> #(1 2 3) asArgumentsIn: [:a :b :c :d | a + b + c + d]<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> "<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""><u style="font-family:"Courier New""></u> <u style="font-family:"Courier New""></u></span></p><p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-CA" style="font-family:"Courier New""> ^aBlock cullWithArguments: self asArray</span><span lang="EN-CA"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-CA">The difference is that it takes a list of any size and picks out the first items and binds them to the variables.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA">I use it often for CSV processing like<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA"> </span><span lang="EN-CA" style="font-family:"Courier New"">(line tokensBasedOn: $;) asArgumentsIn: [:first :second :y | … ].<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-CA">I am just a bit unhappy with the name – it is too long. It reads ok though.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA">The pipe character is an interesting idea. I have to think about it.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-CA">I am use it for a while now and I am very happy with it.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-CA"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-CA">Happy hacking,<u></u><u></u></span></p><p class="MsoNormal"><span>Christian<u></u><u></u></span></p></div></div><div lang="DE" link="#0563C1" vlink="#954F72" style="overflow-wrap: break-word;"><div class="m_-976565113171439616WordSection1"><p class="MsoNormal"><span><u></u> <u></u></span></p><p class="MsoNormal"><span><u></u> <u></u></span></p><div style="border-width:1pt medium medium;border-style:solid none none;padding:3pt 0cm 0cm;border-color:rgb(225,225,225) currentcolor currentcolor"><p class="MsoNormal"><b>Von:</b> Cuis-dev <<a href="mailto:cuis-dev-bounces@lists.cuis.st" target="_blank">cuis-dev-bounces@lists.cuis.st</a>> <b>Im Auftrag von </b>Luciano Notarfrancesco via Cuis-dev<br><b>Gesendet:</b> Mittwoch, 21. Juni 2023 15:13<br><b>An:</b> Discussion of Cuis Smalltalk <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>><br><b>Cc:</b> Luciano Notarfrancesco <<a href="mailto:luchiano@gmail.com" target="_blank">luchiano@gmail.com</a>><br><b>Betreff:</b> [Cuis-dev] Methods that return multiple values<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Smalltalk doesn’t have a convention for methods returning multiple values, and I’m not aware of any implementation.<u></u><u></u></p><div><p class="MsoNormal">An example of such thing is the extended gcd: ‘a xgcd: b’ returns g, s, t where g is the gcd, and as + bt = g. Writing methods that return multiple values is easy with the curly brackets syntax, Integer>>#xgcd: ends with something like<u></u><u></u></p></div><div><p class="MsoNormal"> ^ {g. s. t}<u></u><u></u></p></div><div><p class="MsoNormal">But using sending messages that return multiple values is kind of annoying, I end up doing something like:<u></u><u></u></p></div><div><p class="MsoNormal"> xgcd := a xgcd: b.<u></u><u></u></p></div><div><p class="MsoNormal"> g := xgcd at: 1.<u></u><u></u></p></div><div><p class="MsoNormal"> s := xgcd at: 2.<u></u><u></u></p></div><div><p class="MsoNormal"> t := xgcd at: 3<u></u><u></u></p></div><div><p class="MsoNormal">Some years ago I thought about using blocks for this, but I never tried it. Today I just did a little experiment implementing anArray | aBlock as ‘^ aBlock valueWithPossibleArgs: self’ and I can do:<u></u><u></u></p></div><div><p class="MsoNormal"> (a xgcd: b) | [:g :s :t| … ]<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">This is seems quite nice already, I guess I’ll start using it and see how it feels. But the point of this mail is not to show a solution, but to ask if anyone have thought about this or if they know any nicer solutions. Any ideas?<u></u><u></u></p></div></div></div>-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div></div>