Finding the instance reference of an object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Brady

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

    On Nov 21, 4:33 am, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
    Aaron Brady <castiro...@gma il.comwrote:
    a[:] = [1, 2, 3]
    >
    No, that's not assignment, it's syntactic sugar for a __setslice__
    call.  No copies here.
    >
    Oh dear, perhaps you had better get the Python developers to update the
    grammar that Python uses as that seems to think it's an assignment:
    Well, the docs don't take my side either.

    "object.__setit em__(self, key, value)
    Called to implement assignment to self[key]."

    But wait, is that true assignment?

    "Assignment statements
    Assignment statements are used to (re)bind names to values and to
    modify attributes or items of mutable objects:"

    "If the target is an identifier (name):
    .... the name is bound to the object in the current global namespace."

    The latter is the case of interest.



    Comment

    • greg

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

      Aaron Brady wrote:
      But wait, is that true assignment?
      It's assignment, but it's not really copying an object. No new
      objects are being created -- rather, some of the items within
      the lhs object are being rebound to already-existing objects.

      It would be possible for the lhs object's __setitem__ method
      to be defined so that it created new objects, but then it
      would be the __setitem__ method doing that, not the assignment
      statement itself.

      None of this is really relevant anyway, since the assignment
      that call-by-value implies is always to a bare local name, and
      there is no way that kind of assignment can ever create a new
      object.

      --
      Greg

      Comment

      • greg

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

        Aaron Brady wrote:
        Tell me, what happens during a call to the following C++ function?
        >
        void f( std::vector< int x );
        The same thing as would happen if you wrote

        std::vector<int x = actual_paramete r_expression;
        what happens during a call to the following Python
        function?
        >
        def f( x ): ...
        The same thing as would happen if you wrote

        x = actual_paramete r_expression
        If not, which one is call-by-value?
        They're both call-by-value, because they're both equivalent to
        assignment according to the rules of the language concerned.

        Whether they're "the same" depends on what you mean by "same".
        If you define "same" in such a way that they're not, then that
        definition of "same" is irrelevant to the matter at hand.

        --
        Greg

        Comment

        • greg

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

          Steven D'Aprano wrote:
          You've just *assumed* that assignment in Algol 60 doesn't involving
          copying.
          I've done no such thing. I've *refrained* from assuming that
          the "assignment " in the definition always has to refer to
          Algol 60 assignment. You're the one insisting on tying
          everything to Algol.

          I don't know whether the Algol committee had such a general
          meaning in mind when they wrote that document. It's quite
          likely they weren't thinking that far ahead. But the fact is
          that it *can* be generalized to other languages in an
          obvious and useful way, and many language designers after
          them have generalized it in exactly that way.
          >>(I wait now with bated breath for somebody to point out some Python
          >>implementatio n or feature where assignment doesn't make a copy...)
          >
          Ah crap, I meant *Pascal*.
          Not in plain Pascal, but Apple's Object Pascal (and probably
          other OO Pascal dialects) have object types that are implicitly
          referred to by pointers, like Python objects -- and when you
          pass one by value, only the pointer is copied, not the whole
          object.

          --
          Greg

          Comment

          • Aaron Brady

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

            On Nov 21, 7:06 pm, greg <g...@cosc.cant erbury.ac.nzwro te:
            Aaron Brady wrote:
            Tell me, what happens during a call to the following C++ function?
            >
            void f( std::vector< int x );
            >
            The same thing as would happen if you wrote
            >
               std::vector<int x = actual_paramete r_expression;
            >
            what happens during a call to the following Python
            function?
            >
            def f( x ): ...
            >
            The same thing as would happen if you wrote
            >
               x = actual_paramete r_expression
            >
            If not, which one is call-by-value?
            >
            They're both call-by-value, because they're both equivalent to
            assignment according to the rules of the language concerned.
            No, you have described call-by-equals-sign, or call-by-assignment.
            While call-by-assignment and call-by-value are equivalent in C++, that
            does not make your rule hold for all languages. Python is call-by-
            assignment too, as well as call-by-sharing. Just because a language
            is call-by-assignment, is not sufficient (or necessary) to be call-by-
            value. Call-by-value has other characteristics that Python does not
            meet.

            Comment

            • greg

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

              Aaron Brady wrote:
              Call-by-value has other characteristics that Python does not
              meet.
              The designers of most other dynamic languages don't
              seem to share that opinion, since they use the term
              call-by-value just as though it *does* mean call-
              by-assignment and nothing more.

              --
              Greg

              Comment

              Working...