<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div><span id="transmark" style="display: none; width: 0px; height: 0px;"></span><br>> but what is frozen_tree_set() here, </div><div>frozen_tree_set is my set class.<br><br>> frozensets don't have pop or 'ipop'<br>"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 style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><br>At 2017-02-28 23:19:03, "Ryan Birmingham" <<a href="mailto:rainventions@gmail.com">rainventions@gmail.com</a>> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><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_signature" data-smartmail="gmail_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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;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="m_-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></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></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></wbr>codeofconduct/</a><br></blockquote></div><br></div>
</blockquote></div><br><br><span title="neteasefooter"><p> </p></span></div><br><br><span title="neteasefooter"><p> </p></span>