Finding the instance reference of an object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven D'Aprano

    Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

    On Sat, 15 Nov 2008 19:42:33 -0800, rurpy wrote:
    You are saying there is no objective definition of "value". I disagree.
    I think one can define value in a useful way that is precise,
    objective, and useful.
    No, I'm not saying that there is no objective definition of value. I'm
    saying that the objective definition depends on the circumstances. I
    believe that it is foolish to try to avoid context-sensitivity in your
    definition of value.

    It is possible though. You can consider everything which makes a thing
    different from another thing, but taken all the way that leads to
    deciding that this sentence:

    "The cat sat on the mat."

    does not have the same value as this sentence:

    "The cat sat on the mat."

    because the second one comes further down this document. (I trust that
    you understand that sentences are compound symbols, expressions if you
    prefer.) I would argue that this is usually a silly distinction, since
    the position of a sentence in a document rarely makes a difference to the
    meaning (the value) of that sentence. But not always silly. Imagine the
    following:

    "Harry pointed his massive gun at the fugitive.

    'Do you feel lucky?'

    [... much later on...]

    Working undercover at the casino, Harry adjusted his uniform, brushed a
    speck of imaginary dust off the sleeve, and greeted the billionaire.
    'Good evening Sir, welcome to the Starlight Casino, your first drink is
    on the house. Could I interest you in a game of friendly poker? Do you
    feel lucky?'"

    Is there any doubt that the same symbol can denote a different meaning (a
    value) under different circumstances?


    >I would say that the "everything of interest" I referred to above is
    >the empty set: object() has little or no state. But of course having no
    >state is itself a state, in the same way that 0 is a perfectly good
    >integer.
    >
    "interest" is pretty subjective, isn't it?
    Of course not. If we agree that we want something that undergoes integer
    addition as defined by mathematicians, there's nothing subjective about
    that. That will immediately rule out vast numbers of values: None, dicts,
    lists, strings, and so forth. But it still allows floats, ints, mpz
    objects, etc., and in principle we're indifferent to which of them we
    get. We may choose to arbitrarily convert objects from one type to
    another, whatever is convenient, so long as they can be added together.
    Any other property of these types is a red stripe, to be kept if
    convenient, discarded if needed, but always ignored.


    In the My_int example above,
    is the .foo attribute of interest or not? How would I decide?
    That depends on what you wish to do with the object. If you just want to
    add it to an int, then it is of no interest. It's a red stripe. But if
    you want to pass it on to another function which may treat the foo
    attribute as significant, then you can't afford to just throw it away. In
    other words, you care about the attribute, even if you aren't using it
    yourself.


    >I would say that the answer to this is, "Would you like to include
    >behaviour in value?". Let me give you an example:
    >>
    >class String(string):
    > def upper(self):
    > return "spam"
    >>
    >s1 = "Norwegian Blue"
    >s2 = String("Norwegi an Blue")
    >>
    >Do s1 and s2 have the same value?
    >
    Using my definition of value, the answer is an unambiguous yes.
    But that implies that you should be able to use s2 anywhere that you can
    use s1, and that's clearly not true:

    assert len(s2.upper()) == len(s2)

    Since you can't use s1 and s2 in the same places, how can you justify
    saying the have the same value?

    I have an answer to that: if I don't care about upper(), then I'm happy
    to consider them to have the same value. If I do care about the invariant
    above, then I can't.


    >Using definition (1) above, we can see that the names s1 and s2 refer
    >to different objects, so the names have different values.
    >
    No, they refer to different objects.
    "No"? That's what I said.

    The object str("Norwegian Blue")
    has a value, tucked away inside it somewhere, of some implementation
    defined bits that encode "Norwegian Blue".
    String("Norwegi an Blue") is a subclass of str and has the same value.
    Sure, in the specific example I gave, but in general this is not
    necessarily the case. Consider this fact: every string can be represented
    by a sequence of bytes. A byte can be considered a digit in base 256.
    "Norwegian Blue" considered as a number in this fashion is
    159085770075607 242490043320005 1557. With sufficient effort, I could
    inherit from long, instead of str, and duplicate the exact behaviour as
    str. Subclassing is a red-herring.


    (Actually, we don't really care about bit patterns, it is enough to
    declare that the values stored in the objects are the same because
    that's how the language is defined.) If they appear different when
    .upper() is called, it is because the two types (i.e. behaviors) are
    different.
    But behaviour defines what we interpret the object as. The same bit
    pattern represents the number 159085770075607 242490043320005 1557 and the
    string "Norwegian Blue". Without behaviour, how could you tell them apart?


    >Using definition (2), the objects s1 and s2 have different concrete
    >expressions, and so they are different values. (Remember: the object is
    >the value.)
    >
    Sorry, I disagree.
    >
    >But from definition (3) they both represent that same abstract string,
    >so if I care only about that level of description, I'd say yes they
    >*have* the same value but *are* different values.
    >
    They "have" the same value, it is the difference in their behavior
    (type) that produces different results from .upper().
    >
    class xint (int):
    def bigger(self):
    "return a number bigger than me."
    return self + 2
    class yint (xint):
    def bigger(self):
    "return a number very much bigger than me."
    return self + 1000
    a = xint(5)
    b = yint(5)
    >
    Do you claim that a and b really have different values?
    That depends on why I'm asking. If all I want is a number that I can add
    to 3 and get 8, then I'm indifferent to the choice between a and b and I
    would say that their values are not different in any way I care about. If
    I want a number than I can add to 3, *and* that returns a number larger
    than 1000 when I call the bigger() method, then a will not do but b will
    be fine. In this case, I would argue that their values are different.


    >Assuming I cared about the behaviour of upper(), then s2 is probably
    >not suitable for my purposes and so I would like to distinguish s1 from
    >s2. I'd insist that they have different values which merely looked the
    >same under equality. To use the bank note analogy, then s1 is legal
    >tender but s2 is just a very good forgery.
    >>
    >But note that to a collector of forgeries, s2 might be more valuable
    >than s1, and presumably the writer of class String had a reason for the
    >behaviour given. The answer to the question "do s1 and s2 have
    >different values" will depend on why you are asking.
    >
    That is ok if one is happy with such a squishy, subjective definition of
    value.
    There's nothing subjective about it. Two people, given the same
    constraints, should be able to agree on whether two objects have the same
    value in the context of the problem they are trying to solve.

    But I propose that one can define value in a precise way that
    captures what most people think of as value, and avoids confusing
    objects (or references to them) and the value of objects.
    Good luck. I think you're chasing your own shadow.

    Given that "value" is one of the three defining characteristics of
    objects, a (the?) central concept of Python, I don't see how such a
    subjective definition as yours is workable.
    You've said that attributes are not part of the value, and thus denied
    that the state of an object is the object's value. Given that, I don't
    think your definition is workable. I think it's counter-productive to try
    to define value in such a way that most Python objects have no value,
    especially the most high-level objects.



    --
    Steven

    Comment

    • Steven D'Aprano

      Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

      On Sun, 16 Nov 2008 04:12:53 -0500, Derek Martin wrote:
      On Sun, Nov 16, 2008 at 06:06:20AM +0000, Steven D'Aprano wrote:
      >>* Do all objects have values? (Ignore the Python
      >> docs if necessary.)
      >>
      >If one allows null values, I am current thinking yes.
      >
      I don't see a difference between a "null value" and not having a
      value.
      >>
      [...]
      >It wasn't until the fifth century C.E. that Indian mathematicians
      >invented the concept of zero, and it took many centuries for the idea
      >to get to Europe via the Arabs.
      >
      I think he meant None... Or at least, I personally see a distinction
      between zero and None (and so do the Python docs).
      Of course zero is different from None. For starters, you can't add 1 to
      None.

      Zero is a value,
      Yes it is.
      whereas None is specifically intended to denote the lack of any value.
      None is intended to be *interpreted* by the programmer as the lack of any
      other value. That's what the null object pattern is. MySql has a Null, C
      has null pointers, Pascal has the nil pointer, Python has None, integer
      mathematics has 0, matrix mathematics has any number of identity matrices
      under addition, the ASCII character set has nul... in some older
      programming frameworks, numbers like 9999 or -1 are used. (I remember a
      bug in "Arrow Accounting" that occurred because empty integer fields were
      set to 99 or similar.)

      I
      would, FWIW, only make such a distinction in the context of a computer
      program... Clearly in mathematics and elsewhere, zero is the lack of a
      value (it is the value of nothingness).
      Contradicting your claim above, not to mention about five hundred years
      of European mathematics and about 1500 years of Indian mathematics.

      >"The value of the object is the number of sheep in the paddock, unless
      >the number of sheep is zero, in which case the object has no value..."
      >which is needlessly complicated.
      >
      For conversation, yes... but technically correct.
      No, I would say the value of the object is the number of sheep,
      regardless of whether that number is 0 or 1 or 99.

      >I say that 0 is a perfectly fine value. So is None, [], {}, and any
      >other null-value. I recommend you don't complicate and confuse matters
      >by trying to treat them differently.
      >>

      >
      7.1.2 The None Object
      >
      PyObject * Py_None
      The Python None object, denoting lack of value. This object has no
      methods.

      I would argue that this particular doc is badly worded. Because Python
      doesn't have uninitialized variables, programmers need a value to stand
      in for "I don't have a real value for this yet". By convention, None is
      usually that value, although object() is another reasonable choice, for
      when None is needed for something else.

      The value of a class is it's attributes? Are you saying that
      attributes of an object are part of its value? That would mean that
      'a' and b' below have different values?
      >
      class My_int(int):
      def __init__(self): self.foo = None
      >>
      >That won't work you know.
      >
      Perhaps not, but it illustrates the point. This *does* work:
      >
      >>>class myint(int):
      ... def __init__(self, val):
      ... int.__init__(va l)
      ... self.foo = None
      ...
      >>>b=myint(3)
      >>>b
      3
      >>>b.foo
      >>>print b.foo
      None
      >>>a=3
      >>>a==b
      True
      >
      So, your description of value is not consistent with Python's
      behavior... Python says the two objects I just created have the same
      value. But by your definition, they don't. One of you is wrong... ;-)
      No, Python says that the two objects are equal. That's not the same thing.

      Unicode strings and byte strings are not the same things:
      >>u'3' == '3'
      True

      Consider also:
      >>int(3) == float(3)
      True
      >>decimal.Decim al(3) == int(3)
      True
      >>decimal.Decim al(3) == float(3)
      False


      >That depends on whether the existence of foo makes a difference to you
      >or not. Consider pickle. Since pickle can't predict what aspects of the
      >object are important, it must treat *everything* as significant, and
      >pickle will absolutely treat a and b as having different values.
      >
      I don't think that's clear... pickle will treat a and b as having
      different *data*...
      Define data, and how is it different from value?

      For what it's worth, I think the statement in the
      language reference that all objects have a type, an ID, and a value is
      quite a poor choice of words. Back in 2000, Frederik Lundh put it much
      more accurately, I think:
      >
      http://effbot.org/zone/python-objects.htm
      Yes. For content, you can also say state.


      >I see you are still insisting that value is something that objects
      >"have" rather than "are".
      >
      This falls down, say, for a date object which has the value of the
      string representation of the date when printed, and a numeric value (or
      some other time object) when used in other expressions, both from a
      philisophical and practical standpoint.
      No, the value of a date object is neither its printable string
      representation, nor the implementation-dependent numeric value in seconds.

      Furthermore it falls down semantically; an object has parts that are not
      part of its value, and therefore the value and the object can not be the
      same. The value is merely one attribute (natural language, not Python
      definition) of the object.
      I don't agree that this necessarily follows. We say that the value of an
      symbol is that which the symbol represents. Consider a map, with a little
      radioactive symbol representing a nuclear reactor. Note that the same
      symbol is used for the 100 megawatt CANDU reactor here, and the 2
      megawatt heavy-water research reactor over there: radically different
      things but denoted by the same symbol.

      If protesters cut down the chainlink fence surrounding the power station,
      do we have to gather up all the maps and erase a pixel from the symbol?
      How do we identify which pixel represents the fence and which ones
      represents the reactor core?

      I would answer these questions by saying that for the purposes of the
      map, the chainlink fence is unimportant. The size of the reactor is
      unimportant. We can use the same symbol for both reactors, despite the
      differences, because for the purpose of mapping the only thing that
      matters is the nuclear core. we say that, for the purpose of the map, the
      two sites have the same value. The fence is like an attribute of the
      reactor object, and irrelevant.

      But if you're providing security cameras for the site, then the fence is
      very important. For that purpose, you can't interpret both reactors the
      same. You might have to use a different symbol, say "Reactor 1" and
      "Reactor 2", for them, and you would *not* say that Reactor 1 and Reactor
      2 have the same value.



      --
      Steven

      Comment

      • Steve Holden

        Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

        Steven D'Aprano wrote:
        On Sat, 15 Nov 2008 19:42:33 -0800, rurpy wrote:
        [...]
        >But I propose that one can define value in a precise way that
        >captures what most people think of as value, and avoids confusing
        >objects (or references to them) and the value of objects.
        >
        Good luck. I think you're chasing your own shadow.
        >
        Quite. The question naturally arises "Why would one want to?" This is
        naturally followed by "How would it help if you did?"

        Can't we just get back to programming? If this endless (sigh) discussion
        actually helped anybody to understand how Python worked I could
        sympathize with it.

        regards
        Steve
        --
        Steve Holden +1 571 484 6266 +1 800 494 3119
        Holden Web LLC http://www.holdenweb.com/

        Comment

        • Steve Holden

          Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

          Steven D'Aprano wrote:
          On Sat, 15 Nov 2008 19:42:33 -0800, rurpy wrote:
          [...]
          >But I propose that one can define value in a precise way that
          >captures what most people think of as value, and avoids confusing
          >objects (or references to them) and the value of objects.
          >
          Good luck. I think you're chasing your own shadow.
          >
          Quite. The question naturally arises "Why would one want to?" This is
          naturally followed by "How would it help if you did?"

          Can't we just get back to programming? If this endless (sigh) discussion
          actually helped anybody to understand how Python worked I could
          sympathize with it.

          regards
          Steve
          --
          Steve Holden +1 571 484 6266 +1 800 494 3119
          Holden Web LLC http://www.holdenweb.com/

          Comment

          • Steve Holden

            Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

            Steven D'Aprano wrote:
            On Sat, 15 Nov 2008 11:17:07 -0800, rurpy wrote:
            [...]
            >* How can I find an object's value (if I don't believe
            > .str(), .repr(), etc)? Use gdb. :-)
            >
            I would say the object's value is the value, so if you have the object,
            you have its value.
            [...]
            There's also the question, if you say that an object is different from
            its value, of determining what the value's value is ...

            regards
            Steve
            --
            Steve Holden +1 571 484 6266 +1 800 494 3119
            Holden Web LLC http://www.holdenweb.com/

            Comment

            • Terry Reedy

              Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

              Steven D'Aprano wrote:
              >Because of
              >Python's interpreted nature, names can't be compiled away as in C, they
              >need a concrete runtime existence, but does the language definition need
              >to assume that?
              >
              Of course. It wouldn't be Python if they didn't. However, remember that
              objects don't have names.
              Actually, Python pretty much does compile away names for function
              bodies. (They are replaced by array indexes.) It only needs to
              manifest them for locals(). CPython Dis.dis also accesses them, but
              that is obviously implementation specific. I suspect that the names are
              stored as C char sequences rather than as Python string objects unless
              and until the latter are needed for locals().

              ....
              >>>class EqualsAll(objec t):
              ... def __eq__(self, other):
              ... return True
              ...
              >>>5 == EqualsAll()
              True
              >
              >
              The methods of 5 don't even get called.
              Why do you say that? As I read the manual, type(left-operand).__eq__ is
              called first.
              This of course is a special case, because 5 is a built-in,
              If true, this would be CPython-specific optimization, not language
              definition.
              but in general, the result of x==y depends on *both* x and y.
              True. But type(x) gets first crack at the answer.

              ....
              You're assuming that == compares values, which is often a safe
              assumption, but not always.
              The default is to compare by identity, so assuming otherwise is only
              safe when one knows the classes of x and y to over-ride the default.

              Terry Jan Reedy

              Comment

              • rurpy@yahoo.com

                Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                On Nov 16, 5:12 pm, Steve Holden <st...@holdenwe b.comwrote:
                >The Python Reference Manual states that an object
                >consists of identity, type, and value. "Identity"
                >seems to be non-controversial.
                >>
                >Let's take "type" as meaning the attributes an
                >object inherits from it's class. "value" is then
                >what is left: the object's local attributes and
                >the intrinsic-value described above.
                >>
                >This seems to be the most common view of "value",
                >and similar to the one Fredrik Lundh takes in
                > http://effbot.org/zone/python-objects.htm
                >which was pointed to in an earlier response
                >(he calls it "content")
                >>
                >One could also take all attributes accessible
                >through obj (its class' attributes as well as
                >its local attributes) as "type" leaving only
                >intrinsic-value as "value".
                >This was the view I proposed.
                >>
                >Or one could adopt what Terry Reedy called a
                >4-aspect view: an object is identity, class,
                >value (or local-state or something) and
                >intrinsic-value.
                >>
                >I don't understand Python well enough to defend
                >any of these descriptions (I now realize, despite
                >my previous postings to the contrary. :-)
                >>
                >But what I do defend is the concept of intrinsic
                >value which I have not ever seen explicitly stated
                >anywhere and which clarifies a lot of things for me.
                >>
                >For example, you can define the value of None
                >however you want, but it seems clear that it has
                >(and needs) no intrinsic-value. Same with object().
                >
                In that case I am not sure why this happens:
                >
                >>>a = object()
                >>>b = object()
                >>>a == b
                False
                Who said the equality operator compares values
                and that Python guarantees that it will always
                return True if the values of its arguments are
                the same? You yourself point out below that this
                is not true -- one can define "==" any way
                one wishes. If you can do so, can't the Python
                language developers who implement "==" also do
                so? In fact they did do so in this case, they
                compare id's.

                So the next question is, "why not define value
                equality (and implicitly values) to be whatever
                "==" says it is"? Well you could I suppose. The
                only hard constraints are that it be logically
                consistent, and not lead to erroneous conclusions
                about how Python works. Soft constraints are that
                in be easily understandable, and be intuitive.

                I don't know if using "==" would meet the two hard
                constraints, but it fails the two soft ones.
                The context of the definition of "value" in the
                Language Reference is where the basic properties
                of objects are being described. Why would one
                want to make the definition of objects, the core
                concept of Python, dependent on the behavior of
                the "==" operator?
                Since those objects are of the same type, and since they have no
                "intrinsic value", it would seem you'd expect them to be equal. But they
                aren't, because (in the absence of an explicit equality test method)
                equality is tested for by testing for identity.
                I would expect them to be equal, but apparently
                Python's designers thought otherwise. :-)
                The "==" operator is designed to return results
                that make the most sense (where sense is a
                complicated function in the brains of the Python
                developers.) In calculating that return value,
                Python need not return true for the "same"
                intrinsic values any more than than an object
                you define in Python has to.
                >I now understand why the only way to describe the
                >object int(2) is requires using str/repr whereas
                >with objects without an intrinsic value, I can
                >describe without needing str/repr.
                >I can think of expressions as always returning
                >objects, never "values".
                >Etc...
                >>
                >So, is this point of view any more acceptable?
                >>
                Why not just accept that equality is determined by
                the __eq__ method [2]?
                I do. But equality is not the same as "same-ness"
                [Oh god, here comes another round of philosophical
                discussion. :-)]
                Python can have objects that
                don't equal anything, even themselves, objects that
                are equal to everything, and all definitions in between.
                So "equality" doesn't necessarily mean that the values
                are the same.
                Right! Which is exactly why equality is not the
                right concept for trying to think about, "what are
                the basic aspects of an object?" and "what is the
                value of an object?".
                If objects have values that differ from the object itself, then aren't
                those values themselves objects? If so, what are the values of those
                objects?
                Yes, the intrinsic value of a list object contains
                (references to) other objects. But note that I did
                not claim to say *what* an instrinsic value was or
                what it's value was, only that:
                * it exists (in some but not all objects).
                * builtin[*3] methods and functions can access
                it and use it to decide what they will return.
                * that it is not accessible from Python language
                directly, only though the behavior of the those
                builtin methods/functions.[*4]
                * That however you define "value" in the P.L.R.
                sense) it must include intrinsic value (if any)
                So however P.L.R. "value" is defined, it must be
                recursive (i.e. the value of [1, [2, 3]] is different
                than [1, [2, 4]].)

                [*3] Again, I do not have a good term for this but
                mean code that is part of the implementation: for
                C-Python that would be C-API code that can directly
                access an object's implementation.

                [*4] That should probably be "may not be accessible..."
                since I could imagine an implementation like PyPy
                representing such "hidden state" using regular Python
                objects.
                regards
                Steve
                >
                >[*1] I took note of Terry Reedy's point that
                >a.__add__(b) is really int.__add__ (a, b) but
                >since the two descriptions are isomorphic at
                >the level I am discussing, it seemed clearer
                >to leave class out of it.
                >
                [2] This is a simplification, since the interpreter will fall back on
                other methods in the absence of __eq__.

                Comment

                • Terry Reedy

                  Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                  rurpy@yahoo.com wrote:
                  Or one could adopt what Terry Reedy called a
                  4-aspect view: an object is identity, class,
                  value (or local-state or something) and
                  intrinsic-value.
                  What I specifically said is id, class, instance attributes, and private
                  data. So objects have only one, some only the other, some both, and
                  some neither. I also noted that the boundary between properties and
                  instance methods of the class and attributes of the instance is somewhat
                  flexible.

                  I think the important point is this. In Python, objects are
                  self-identifying bundles of information, which is to say, the bundle
                  includes knowledge of the which universe of possible bundles the object
                  comes from, where the universe includes a set of operations. This is
                  sometimes called RTTI -- run-time type information. This is in contrast
                  to other languages and signal-processors where information
                  (bit-patterns) is usually *not* self-identifying, but the universe must
                  be somehow enforced by a compiler or carried in the context. In C, for
                  instance, most types cannot have RTTI and RTTI is only required for
                  unions. Programmers can give structs a type field and that is how
                  CPython implements PyObjects.

                  Terry Jan Reedy

                  Comment

                  • Hendrik van Rooyen

                    Re: Official definition of call-by-value (Re: Finding theinstancerefe rence...)

                    "Steve Holden" <steve@ho.omwro te:
                    There's also the question, if you say that an object is different from
                    its value, of determining what the value's value is ...
                    This one is easy - its obviously the value that is returned when the value
                    is returned when you call for the value that you are interested in, unless
                    you are interested in the bare value, in which case its the value that is
                    returned.

                    I am beginning to suspect that Steven de'A is hammering away at this
                    to take his mind off the recent cricket game between his country's team
                    and India. Anything is better than contemplating that. It was enough to
                    shake one's faith in Southern Supremacy...

                    :-)

                    - Hendrik

                    --
                    And there was wailing and gnashing of teeth...


                    Comment

                    • Hendrik van Rooyen

                      Re: Official definition of call-by-value (Re: Finding theinstancerefe rence...)

                      "Terry Reedy" <tjreedy@udel.e duwrote:
                      I think the important point is this. In Python, objects are
                      self-identifying bundles of information, which is to say, the bundle
                      includes knowledge of the which universe of possible bundles the object
                      comes from, where the universe includes a set of operations. This is
                      sometimes called RTTI -- run-time type information. This is in contrast
                      to other languages and signal-processors where information
                      (bit-patterns) is usually *not* self-identifying, but the universe must
                      be somehow enforced by a compiler or carried in the context.
                      This is an important distinction, and it goes even deeper - in some
                      low level code, the "organisati on" consists solely of a priori knowledge
                      in the mind of the assembler or C programmer - that is also why it is so
                      difficult to understand machine code - the individual instructions may
                      be well defined, but because there is no obvious context, it is hard
                      to figure out what the original programmer's intentions were.
                      In C, for
                      instance, most types cannot have RTTI and RTTI is only required for
                      unions. Programmers can give structs a type field and that is how
                      CPython implements PyObjects.
                      Yes, and for some objects, part of that struct is the piece that is
                      effectively the "value" field, and the content of that is what the
                      value is.

                      And here one is faced with the same problem as I pointed to above -
                      if you do not have access to the struct definition (which you
                      don't have at run time), its kind of difficult to figure out where
                      the value is, and you can only access it via the public methods
                      supplied, if any.

                      - Hendrik


                      Comment

                      • rurpy@yahoo.com

                        Re: Official definition of call-by-value (Re: Finding theinstancerefe rence...)

                        On Nov 17, 12:20 pm, "Hendrik van Rooyen" <m...@microcorp .co.za>
                        wrote:
                        "Steve Holden" <steve@ho.omwro te:
                        >
                        >There's also the question, if you say that an object is different from
                        >its value, of determining what the value's value is ...
                        >
                        This one is easy - its obviously the value that is returned when the value
                        is returned when you call for the value that you are interested in, unless
                        you are interested in the bare value, in which case its the value that is
                        returned.
                        Except of course, values are *never* returned,
                        only objects. This is why the concept of an object's
                        intrinsic value is important. I now understand
                        that at some point when chasing values, you will
                        eventually[*1] encounter an object with no intrinsic
                        value or one for which you have to rely on repr()
                        to tell you its value; there is no other way to
                        examine it from the "outside" since (in C-Python)
                        its value in in a form only C-level code can
                        understand.

                        [*1] Excluding circularly linked chains of values
                        of course.

                        Comment

                        • Craig Allen

                          Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                          * Do all objects have values? (Ignore the Python
                          docs if necessary.)
                          >
                          If one allows null values, I am current thinking yes.
                          >
                          I don't see a difference between a "null value"
                          and not having a value.
                          >
                          I think the difference is concrete... an uninitialized variable in C
                          has no value, I'd say, because the value it will have is
                          indeterminate, it will be whatever happens to be sitting at that
                          location in memory, inconsistent. If that variable is initialized to
                          some value representing "none", like NULL, then it has a consistent
                          value of "none". There is no way to have an uninitialized variable in
                          python, so they are always consistently set, so they always have
                          values.

                          ?

                          Comment

                          • Aaron Brady

                            Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                            On Nov 17, 8:35 pm, Craig Allen <callen...@gmai l.comwrote:
                            >* Do all objects have values? (Ignore the Python
                            > docs if necessary.)
                            >
                            If one allows null values, I am current thinking yes.
                            >
                            I don't see a difference between a "null value"
                            and not having a value.
                            >
                            I think the difference is concrete... an uninitialized variable in C
                            has no value, I'd say, because the value it will have is
                            indeterminate, it will be whatever happens to be sitting at that
                            location in memory, inconsistent.  If that variable is initialized to
                            some value representing "none", like NULL, then it has a consistent
                            value of "none".  There is no way to have an uninitialized variable in
                            python, so they are always consistently set, so they always have
                            values.
                            >
                            ?
                            If he was dying, he wouldn't have bothered to carve 'Aaaauuuggghhhh '.
                            He'd just say it.

                            #269 and counting!

                            Comment

                            • Steven D'Aprano

                              Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                              On Sun, 16 Nov 2008 23:34:58 -0500, Terry Reedy wrote:
                              Steven D'Aprano wrote:
                              >>>>class EqualsAll(objec t):
                              >... def __eq__(self, other):
                              >... return True
                              >...
                              >>>>5 == EqualsAll()
                              >True
                              >>
                              >>
                              >The methods of 5 don't even get called.
                              >
                              Why do you say that? As I read the manual, type(left-operand).__eq__ is
                              called first.
                              Ah, I could be confabulating that with arithmetic operators __add__ etc.
                              It may be that comparisons use a different mechanism:
                              >>5 .__cmp__(Equals All())
                              Traceback (most recent call last):
                              File "<stdin>", line 1, in <module>
                              TypeError: int.__cmp__(x,y ) requires y to be a 'int', not a 'EqualsAll'



                              --
                              Steven

                              Comment

                              • Steven D'Aprano

                                Re: Official definition of call-by-value (Re: Finding the instancereferen ce...)

                                On Mon, 17 Nov 2008 18:35:04 -0800, Craig Allen wrote:
                                >* Do all objects have values? (Ignore the Python
                                > docs if necessary.)
                                >>
                                If one allows null values, I am current thinking yes.
                                >>
                                >I don't see a difference between a "null value" and not having a value.
                                >>
                                >>
                                I think the difference is concrete... an uninitialized variable in C has
                                no value, I'd say, because the value it will have is indeterminate, it
                                will be whatever happens to be sitting at that location in memory,
                                inconsistent. If that variable is initialized to some value
                                representing "none", like NULL, then it has a consistent value of
                                "none". There is no way to have an uninitialized variable in python, so
                                they are always consistently set, so they always have values.
                                >
                                ?
                                Well said.

                                I'd even go so far as to say that an uninitialized variable in C has a
                                random value, unless the compiler prevents you from accessing it. If the
                                compiler lets you (accidentally, I assume!) do something with an
                                uninitialized variable, then you're accessing whatever random value it
                                happens to get.


                                --
                                Steven

                                Comment

                                Working...