<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<br>
<div class="moz-cite-prefix">On 23/01/17 04:27 PM, Gerald Britton
wrote:<br>
</div>
<blockquote
cite="mid:CAPxRSnb3xOQDM8KUzQ96HUiFZnrqrPC7uLUmf4_YiPqxnzSpRQ@mail.gmail.com"
type="cite">
<div dir="auto">
<div><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Jan 23, 2017 1:12 PM, "Britton,
Gerald" <<a moz-do-not-send="true"
href="mailto:Gerald.Britton@td.com">Gerald.Britton@td.com</a>>
wrote:<br type="attribution">
<blockquote class="quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US">
<div class="m_7657605112096263134WordSection1">
<pre><span style="color:black">On 23/01/17 02:56 PM, Gerald Britton wrote:</span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> On Jan 23, 2017 11:07 AM, "Soni L." <<a moz-do-not-send="true" href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">fakedme+py at gmail.com</a> </i></span></pre>
<pre><span style="color:black">><i> <mailto:<a moz-do-not-send="true" href="mailto:fakedme%25" target="_blank">fakedme%</a><a moz-do-not-send="true" href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">2Bpy at gmail.com</a>>> wrote:</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> On 23/01/17 01:52 PM, Gerald Britton wrote:</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> [snip]</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> >I propose `x .= y` -> `x = x . y`, for any `y`.</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> [snip]</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> I think you mean "any y that is a member of x"</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> Since it desugars into `x = x.y`, you can literally use anything</i></span></pre>
<pre><span style="color:black">><i> for `y`.</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> x .= __call__().whatever().unwrap() * 3</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> is equivalent to</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> x = x.__call__().whatever().<wbr>unwrap() * 3</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> and</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> x .= 1</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> is equivalent to</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> x = x.1</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> which is equivalent to</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> SyntaxError: invalid syntax</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">>><i> Also, note that this syntax means that x will be rebound to</i></span></pre>
<pre><span style="color:black">>><i> the result of calling x.y, whatever that is (frequently,</i></span></pre>
<pre><span style="color:black">>><i> None, for mutating methods)</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> In general, you can't count on methods to return references</i></span></pre>
<pre><span style="color:black">>><i> to their instances, even though it's handy for fluent coding,</i></span></pre>
<pre><span style="color:black">>><i> so this side effect may be unexpected to some</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> This is why it's for use with **immutable** objects.</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">>><i> That's a problem with your original example:</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> >long_name = mkbuilder()</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> >long_name = long_name.seta(a)</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> >long_name = long_name.setb(b)</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> >y = long_name.build()</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> What do the methods seta and setb return? If they don't</i></span></pre>
<pre><span style="color:black">>><i> return "self" you've got a problem. I think.</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> They don't return self. Ever. The value bound to long_name is</i></span></pre>
<pre><span style="color:black">><i> immutable, like an integer. They return a new instance.</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> Then long_name isn't immutable. It changes with every line. That can </i></span></pre>
<pre><span style="color:black">><i> lead to nasty bugs if you count on its immutability.</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> Easy to see. Just print long_name after each call.</i></span></pre>
<pre><span style="color:black"> </span></pre>
<pre><span style="color:black">You're mixing up value immutability with name immutability. The name </span></pre>
<pre><span style="color:black">isn't immutable, but:</span></pre></div></div></blockquote></div></div></div><div dir="auto">
</div><div dir="auto">Er...No. I'm not confused at all, unless you define immutability in a new way.. you said that the "value bound to long_name is immutable." It's not. Your example below proves it. </div><div dir="auto">
</div><div dir="auto">An immutable object is one whose state cannot be modified once set. That's not happening here. The state of the object bound to long_name, which is a pointer to an instance of you class, changes with each line.</div></div></blockquote>
Python has pointers now?!
The value pointed to by the value bound to long_name is immutable. Can you stop being so pedantic? >.<
<blockquote cite="mid:CAPxRSnb3xOQDM8KUzQ96HUiFZnrqrPC7uLUmf4_YiPqxnzSpRQ@mail.gmail.com" type="cite"><div dir="auto"><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-US"><div class="m_7657605112096263134WordSection1"><pre><span style="color:black"></span></pre>
<pre><span style="color:black"> </span></pre>
<pre><span style="color:black">long_name = mkbuilder()</span></pre>
<pre><span style="color:black">x = long_name</span></pre>
<pre><span style="color:black">long_name .= seta("a")</span></pre>
<pre><span style="color:black">y = long_name</span></pre>
<pre><span style="color:black">long_name .= setb("b")</span></pre>
<pre><span style="color:black">z = long_name</span></pre>
<pre><span style="color:black">print(x) # a = None, b = None</span></pre>
<pre><span style="color:black">print(y) # a = "a", b = None</span></pre>
<pre><span style="color:black">print(z) # a = "a", b = "b"</span></pre>
<pre><span style="color:black">print(x is y) # False</span></pre>
<pre><span style="color:black">print(x is z) # False</span></pre>
<pre><span style="color:black">print(y is z) # False</span></pre>
<pre><span style="color:black">print(long_name is z) # True</span></pre>
<pre><span style="color:black"> </span></pre>
<pre><span style="color:black">See also:</span></pre>
<pre><span style="color:black"> </span></pre>
<pre><span style="color:black">long_name = 1</span></pre>
<pre><span style="color:black">x = long_name</span></pre>
<pre><span style="color:black">long_name += 1</span></pre>
<pre><span style="color:black">y = long_name</span></pre>
<pre><span style="color:black">long_name += 1</span></pre>
<pre><span style="color:black">z = long_name</span></pre>
<pre><span style="color:black">print(x) # 1</span></pre>
<pre><span style="color:black">print(y) # 2</span></pre>
<pre><span style="color:black">print(z) # 3</span></pre>
<pre><span style="color:black">print(x is y) # False</span></pre>
<pre><span style="color:black">print(x is z) # False</span></pre>
<pre><span style="color:black">print(y is z) # False</span></pre>
<pre><span style="color:black">print(long_name is z) # True</span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">>><i> FWIW why can't you just write:</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> x.y</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> or for your example:</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> long_name.seta(a)</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> ?</i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">>><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> See the IRC bot builder example, it should be more clear. (It's</i></span></pre>
<pre><span style="color:black">><i> about forking the builder.)</i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black">><i> </i></span></pre>
<pre><span style="color:black"> </span></pre>
</div>
<p><font style="font-size:8pt" face="Arial">
If you wish to unsubscribe from receiving commercial electronic messages from TD Bank Group, please click <a moz-do-not-send="true" href="http://www.td.com/tdoptout" target="_blank">here</a> or go to the following web address: <a moz-do-not-send="true" href="http://www.td.com/tdoptout" target="_blank">www.td.com/tdoptout</a>
Si vous souhaitez vous désabonner des messages électroniques de nature commerciale envoyés par Groupe Banque TD veuillez cliquer <a moz-do-not-send="true" href="http://www.td.com/tddesab" target="_blank">ici</a> ou vous rendre à l'adresse <a moz-do-not-send="true" href="http://www.td.com/tddesab" target="_blank">www.td.com/tddesab</a>
</font></p>
<p><font style="font-size:8pt" face="Arial">
NOTICE: Confidential message which may be privileged. Unauthorized use/disclosure prohibited. If received in error, please go to <a moz-do-not-send="true" href="http://www.td.com/legal" target="_blank">www.td.com/legal</a> for instructions.
AVIS : Message confidentiel dont le contenu peut être privilégié. Utilisation/divulgation interdites sans permission. Si reçu par erreur, prière d'aller au <a moz-do-not-send="true" href="http://www.td.com/francais/avis_juridique" target="_blank">www.td.com/francais/avis_<wbr>juridique</a> pour des instructions.</font></p>
</div>
</blockquote></div>
</div></div></div>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre wrap="">_______________________________________________
Python-ideas mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org">Python-ideas@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a>
Code of Conduct: <a class="moz-txt-link-freetext" href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></pre>
</blockquote>
</body></html>