Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45542
| Date | 2013-05-19 11:54 +1000 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: mutable ints: I think I have painted myself into a corner |
| References | <CAPTjJmrgFGP=4pHXN7cKRzZ4pNg1Yeki=iPFw9bRLDF-osYAaA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1828.1368928471.3114.python-list@python.org> (permalink) |
On 19May2013 11:11, Chris Angelico <rosuav@gmail.com> wrote:
| On Sun, May 19, 2013 at 10:26 AM, Cameron Simpson <cs@zip.com.au> wrote:
| > Before I toss this approach and retreat to my former "object"
| > technique, does anyone see a way forward to modify an int subclass
| > instance in place? (That doesn't break math, preferably; I don't
| > do arithmetic with these things but they are, after all, ints...)
|
| Why is it an int subclass? Because there are places where you want to
| use it as though it were an int? It might be easier to render those,
| instead, eg by creating a __int__ method. (Or is it "an __int__
| method"? Not sure.)
I don't want to use it as an int, on the outside. I want to use an
int on the inside as the implementation.
It's an int _subclass_ so that it is no bigger than an int. Otherwise
I may as well just make an ordinary object and be back where I
started. Bulky:-(
The reason it is an _int_ subclass, versus something else, is that
a bitmap is a type of int. So the functional mapping is direct.
I _do_ _not_ want to operate on it from the outside as an int (doing
overt addition, for example, though I can imagine doing bitwise
activities); I want to operate on in _internally_ as a int to decide
what names-by-an-attribute flags are on or off.
So an object with an __int__() method is right out; it's the wrong
interface because it would mean an int() call (possibly implicit)
in exterior code.
Cheers,
--
Cameron Simpson <cs@zip.com.au>
Hoping to shave precious seconds off the time it would take me to get
through the checkout process and on my way home, I opted for the express
line ("9 Items Or Less [sic]" Why nine items? Where do they come up with
these rules, anyway? It's the same way at most stores -- always some
oddball number like that, instead of a more understandable multiple of
five. Like "five.")
- Geoff Miller, geoffm@purplehaze.Corp.Sun.COM
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: mutable ints: I think I have painted myself into a corner Cameron Simpson <cs@zip.com.au> - 2013-05-19 11:54 +1000
Re: mutable ints: I think I have painted myself into a corner Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-05-20 13:23 +1200
Re: mutable ints: I think I have painted myself into a corner Cameron Simpson <cs@zip.com.au> - 2013-05-20 16:07 +1000
csiph-web