Optional parameter object re-used when instantiating multiple objects

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

    #31
    Re: Optional parameter object re-used when instantiating multipleobjects

    On Thu, 20 Nov 2008 04:42:24 -0800, Aaron Brady wrote:
    On Nov 19, 7:58 pm, alex23 <wuwe...@gmail. comwrote:
    >On Nov 20, 10:14 am, Aaron Brady <castiro...@gma il.comwrote:
    >>
    If you had a menu in a browser interface that had the items, say,
    'Stop' and 'Reload', what would you expect to happen if you clicked
    on them?
    >>
    >If you had a keyword called 'def', which defined functions, would you
    >expect it to define said functions when it executed, or on each
    >function call?
    >
    At first, I would expect it to define them at compile-time. Then, when
    I learned there was no such thing,
    Of course there is compile-time. When did you think the .pyc files got
    created?

    The same thing happens in the interactive interpreter: the function is
    compiled to byte-code, and then the compiled function is executed by the
    VM.



    --
    Steven

    Comment

    • alex23

      #32
      Re: Optional parameter object re-used when instantiating multipleobjects

      On Nov 21, 10:07 am, Aaron Brady <castiro...@gma il.comwrote:
      Why, I would expect the interpreter to define the functions when it
      first hits the def, that is, at the point of definition.
      Then why are you arguing that the parameters should be re-defined at
      the point of calling?

      Comment

      • Chris Rebert

        #33
        Re: Optional parameter object re-used when instantiating multipleobjects

        On Thu, Nov 20, 2008 at 9:26 PM, alex23 <wuwei23@gmail. comwrote:
        On Nov 21, 10:07 am, Aaron Brady <castiro...@gma il.comwrote:
        >Why, I would expect the interpreter to define the functions when it
        >first hits the def, that is, at the point of definition.
        >
        Then why are you arguing that the parameters should be re-defined at
        the point of calling?
        I would assume because using the "def is start of definition" theory,
        anything after the "def" is part of the function definition/body and
        should not be immediately executed, but rather be executed at
        call-time. The function body comes after the "def" and doesn't get run
        immediately, so neither should the default argument values.

        I take no position on the virtue of said theory.

        Cheers,
        Chris
        --
        Follow the path of the Iguana...

        Comment

        • Aaron Brady

          #34
          Re: Optional parameter object re-used when instantiating multipleobjects

          On Nov 20, 11:26 pm, alex23 <wuwe...@gmail. comwrote:
          On Nov 21, 10:07 am, Aaron Brady <castiro...@gma il.comwrote:
          >
          Why, I would expect the interpreter to define the functions when it
          first hits the def, that is, at the point of definition.
          >
          Then why are you arguing that the parameters should be re-defined at
          the point of calling?
          Hmm. You have conflated defining the function with defining the
          parameters.

          My argument is that the syntax doesn't obviously imply either
          interpretation.

          I advocate a 'nonstatic' decorator. Also, I don't think a 'static'
          decorator, had Python taken the other interpretation, would have been
          that bad a combination.

          Comment

          • alex23

            #35
            Re: Optional parameter object re-used when instantiating multipleobjects

            On Nov 21, 7:49 pm, Aaron Brady <castiro...@gma il.comwrote:
            On Nov 20, 11:26 pm, alex23 <wuwe...@gmail. comwrote:
            >
            On Nov 21, 10:07 am, Aaron Brady <castiro...@gma il.comwrote:
            >
            Why, I would expect the interpreter to define the functions when it
            first hits the def, that is, at the point of definition.
            >
            Then why are you arguing that the parameters should be re-defined at
            the point of calling?
            >
            Hmm.  You have conflated defining the function with defining the
            parameters.
            No, I think I've made the mistake of joining yet another pointless
            thread arguing about semantics.

            Comment

            • Aaron Brady

              #36
              Re: Optional parameter object re-used when instantiating multipleobjects

              On Nov 21, 4:24 am, alex23 <wuwe...@gmail. comwrote:
              On Nov 21, 7:49 pm, Aaron Brady <castiro...@gma il.comwrote:
              >
              On Nov 20, 11:26 pm, alex23 <wuwe...@gmail. comwrote:
              >
              On Nov 21, 10:07 am, Aaron Brady <castiro...@gma il.comwrote:
              >
              Why, I would expect the interpreter to define the functions when it
              first hits the def, that is, at the point of definition.
              >
              Then why are you arguing that the parameters should be re-defined at
              the point of calling?
              >
              Hmm.  You have conflated defining the function with defining the
              parameters.
              >
              No, I think I've made the mistake of joining yet another pointless
              thread arguing about semantics.
              I was making the case that the options were about the same. Then you
              had some questions.

              I said, I would expect the interpreter to define the functions at a
              certain time.

              You asked, why are you arguing that the parameters should be re-
              defined at a different time.

              You assumed that defining a function and defining its parameters
              necessarily happen at the same time. Not so.

              Comment

              Working...