[Python-ideas] unify usage of mutable and immutable objects

语言破碎处 mlet_it_bew at 126.com
Tue Feb 28 13:13:59 EST 2017


> That is simply misspelled for your intent.


Take a look at the following function in Haskell (GHC) Data.Set
    minView :: Set a -> Maybe (a, Set a)
We always want the new set after a immutable set pop().
    "e = a.pop()" is fine for mutable set, but not for immutable case.
    we need "e, a = a.pop()" to update "a".







在 2017-03-01 01:23:54,"David Mertz" <mertz at gnosis.cx> 写道:

On Tue, Feb 28, 2017 at 5:59 AM, 语言破碎处 <mlet_it_bew at 126.com> wrote:

bad example:
    a = set()
    a.add(1)        # return None; "a" changed
    e = a.pop();



That is simply misspelled for your intent.


a = set()
a |= {1}
e = a.pop()




--

Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/48e79401/attachment.html>


More information about the Python-ideas mailing list