<div dir="ltr">So it sounds like what you want is this:<div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">In [30]: class FrozenSet(frozenset):</font></div><div><font face="monospace, monospace">    ...:     def pop(self):</font></div><div><font face="monospace, monospace">    ...:         item = next(iter(self))</font></div><div><font face="monospace, monospace">    ...:         return item, self-{item}</font></div><div><font face="monospace, monospace">    ...:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [31]: a = FrozenSet({1,2,3,4,5})</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [32]: a.pop()</font></div><div><font face="monospace, monospace">Out[32]: (1, frozenset({2, 3, 4, 5}))</font></div></div></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">I think I'm +1 on `frozenset` itself growing that method.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 10:13 AM, 语言破碎处 <span dir="ltr"><<a href="mailto:mlet_it_bew@126.com" target="_blank">mlet_it_bew@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:arial"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:arial"><span class="gmail-"><div><span id="gmail-m_7386042691703221577transmark" style="display:none;width:0px;height:0px"></span><br>> but what is frozen_tree_set() here, </div></span><div>frozen_tree_set is my set class.<span class="gmail-"><br><br>> frozensets don't have pop or 'ipop'<br></span>"frozen" means we don't modify the object, but we can use it as prototype to create new object.<br>    e.g. in Haskell:  val {attr = 1} or in Python: namedtuple._replace<br>frozensets can have pop(), but the hash implement will be O(n).<br><br>> what is ipop?<br>when we pop element from frozensets, we get a element and a new set.<br><br><br></div><div><div class="gmail-h5"><div style="zoom:1"></div><div id="gmail-m_7386042691703221577divNeteaseMailCard"></div><br>At 2017-02-28 23:19:03, "Ryan Birmingham" <<a href="mailto:rainventions@gmail.com" target="_blank">rainventions@gmail.com</a>> wrote:<br> <blockquote id="gmail-m_7386042691703221577isReplyContent" style="padding-left:1ex;margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)"><div dir="ltr">I'm sorry for the confusion, but what is frozen_tree_set() here, and what is ipop? frozensets don't have pop or 'ipop', so my apologies that I'm a bit lost here.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail-m_7386042691703221577gmail_signature">-Ryan Birmingham<br></div></div>
<br><div class="gmail_quote">On 28 February 2017 at 08:59, 语言破碎处 <span dir="ltr"><<a href="mailto:mlet_it_bew@126.com" target="_blank">mlet_it_bew@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:arial"><br>Hi!<br>    I write a '<'-based immutable set class.<br>    But it is quit different from the standard set class.<br>    I wish collections.abc.Set be more friendly to immutable tree sets or<br>    Python add new syntax to unify such difference.<br><span id="gmail-m_7386042691703221577m_-281119328831140083transmark" style="display:none;width:0px;height:0px"></span><br><br>good example:<br>    a = []<br>    a += a  # "a" is the original list<br><br>    a = ()<br>    a += a  # "a" is a new tuple<br><br>bad example:<br>    a = set()<br>    a.add(1)        # return None; "a" changed<br>    e = a.pop();<br><br>    a = frozen_tree_set()<br>    a = a.add(1)    # return another set;<br>    e, a = a.ipop() # return two objects instead of one!<br><br>solution I used:<br>    a <<= 1         # <==> a = a.add(1)<br>    but "a.ipop()" ....<br>my current solution is to write a wrapper class<br>    to turn immutable set into mutable set, <br>    but it is so noisy to box and unbox.<br><br><br>solution that I wish:<br>    a :=.add(1)      # "=." mimic "+="; return the result object<br>    e ~ a :=.pop()<br><br>    d[key] :=.add(1) # in dict<br><br><br><br>if only python add following features:<br>1) modify the original object<br>    1-0)<br>        1) define:<br>        def .method(self):...<br>        # "." means "intend to modify self"<br>        #       return any thing<br>        # to avoid immutable method<br>        #       which was intended to return new object<br>        #       leave self unchanged<br><br>        2) invoke:<br>        r = a..method();<br>    1-1) ignore result<br>        # no matter what returned, discard it<br>        a.-.method();           # <==> [a..method(), None][-1]<br>    1-2) return self<br>        # no matter what returned, return self<br>        a.>.method().>.method();# <==> [a..method(), a..method(), a][-1]<br><br><br>2) create new object<br>    2-0)<br>        1) define<br>        # intend to return (result, new object)<br>        def ^method():...<br><br>        2)invoke:<br>        r, a' = a.^method();<br>    2-1) return other, discard result<br>        a.-^method().-^method();# <==> a.^method()[1].^method()[1];<br>    2-2) assign other to original variable<br>        a=^method();            # <==> a = a.^method()[1];<br><br>3) unify both:<br>    a :=.method();<br>    # if   defined ".method" then "a..method();"<br>    # elif defined "^method" then "a = a.^method()[1];"<br>    # elif defined  "method" then "a.method();"<br>    # else error<br><br>    r ~ a :=.method();<br>    # if   defined ".method" then "r = a..method();"<br>    # elif defined "^method" then "r, a = a.^method();"<br>    # elif defined  "method" then "r = a.method();"<br>    # else error<br><br><br><br><br></div><br><br><span title="neteasefooter"><p> </p></span><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br></blockquote></div><br></div>
</blockquote></div></div></div><br><br><span title="neteasefooter"><p> </p></span></div><br><br><span title="neteasefooter"><p> </p></span><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div></div>