<div dir="ltr"><div class="gmail_default" style="font-size:small">On Tue, May 1, 2018 at 3:36 AM, Chris Jerdonek <span dir="ltr"><<a href="mailto:chris.jerdonek@gmail.com" target="_blank">chris.jerdonek@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Apr 26, 2018 at 10:33 AM, Sven R. Kunze <<a href="mailto:srkunze@mail.de">srkunze@mail.de</a>> wrote:<br>
> On 25.04.2018 01:19, Steven D'Aprano wrote:<br>
>><br>
>> Sorry, gcd(diff, n) is not the "perfect name", and I will tell you that<br>
>> sometimes g is better. [...]<br>
><br>
> We were talking about the real-world code snippet of Tim (as a justification<br>
> of := ) and alternative rewritings of it without resorting to new syntax.<br>
<br>
</span>Apologies if this idea has already been discussed (I might have missed<br>
the relevant email), but thinking back to Tim's earlier example--<br>
<br>
    if (diff := x - x_base) and (g := gcd(diff, n)) > 1:<br>
        return g<br>
<br>
it occurs to me this could be implemented with current syntax using a<br>
pattern like the following:<br>
<br>
    stashed = [None]<br>
<br>
    def stash(x):<br>
        stashed[0] = x<br>
        return x<br>
<br>
    if stash(x - x_base) and stash(gcd(stashed[0], n)) > 1:<br>
        return stashed[0]<br>
<br>
There are many variations to this idea, obviously. For example, one<br>
could allow passing a "name" to stash(), or combine stash / stashed<br>
into a single, callable object that allows setting and reading from<br>
its store. I wonder if one of them could be made into a worthwhile<br>
pattern or API..<div class="gmail_default" style="font-size:small;display:inline">​.</div></blockquote><div><br></div><div class="gmail_default" style="font-size:small">​I hope you don't think this recasting, is in any way less confusing to a beginner than an inline assignment. This is language abuse!</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In any case, what advantages would it have over simply declaring "stashed" as a global inside the function and omitting the confusing subscripting?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">regards</div><div class="gmail_default" style="font-size:small"> Steve​</div></div></div></div>