Avoiding local variable declarations?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc 'BlackJack' Rintsch

    #16
    Re: Avoiding local variable declarations?

    On Mon, 17 Nov 2008 10:10:16 +0000, Jorgen Grahn wrote:
    On Thu, 13 Nov 2008 12:49:02 -0800 (PST), dpapathanasiou
    <denis.papathan asiou@gmail.com wrote: ...
    >>but what's wrong with you original code?
    >>
    >I come from a functional programming school of thought, where you avoid
    >local variable declarations if at all possible.
    >
    I'm not sure that's universal. Using Standard ML at Uni, it was often
    useful to use "let name = expr in expr" (or whatever the syntax was) to
    simplify an expression. Directly borrowed from mathematics, I assume.
    That's (also?) Haskell syntax and I agree that it is useful to write
    readable code.
    'name' is not a variable, of course; there are no variables in
    functional programming. Can't remember what it's called -- named
    expression, maybe?
    I think it's called variable and works like variables work in
    mathematics, i.e. you can assign only once. Not such illogical crap like
    ``a = a + 1`` which must be obviously false unless 1 is defined as the
    neutral element for the definition of ``+`` here. :-)

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Steven D'Aprano

      #17
      Re: Avoiding local variable declarations?

      On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
      Not such illogical crap like
      ``a = a + 1`` which must be obviously false unless 1 is defined as the
      neutral element for the definition of ``+`` here.
      I don't quite know what you mean by "neutral element". I think you mean
      the identity element under addition, which is zero, but that doesn't work:

      0 = 0 + 1

      Obviously not.

      I think the only workable answer might be a = infinity, but that has two
      problems: (1) infinity isn't a valid integer or real number (although
      there is a valid float representing infinity on many platforms); and (2)
      which infinity? Aleph 0, aleph 1, c, ... There's an infinite number of
      them.



      --
      Steven

      Comment

      • Gabriel Genellina

        #18
        Re: Avoiding local variable declarations?

        En Mon, 17 Nov 2008 22:18:51 -0200, Steven D'Aprano
        <steven@remove. this.cybersourc e.com.auescribi ó:
        On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
        >
        >Not such illogical crap like
        >``a = a + 1`` which must be obviously false unless 1 is defined as the
        >neutral element for the definition of ``+`` here.
        >
        I don't quite know what you mean by "neutral element". I think you mean
        the identity element under addition, which is zero, but that doesn't
        work:
        >
        0 = 0 + 1
        >
        Obviously not.
        Perhaps you didn't read carefully the above post? He said "unless *1* is
        defined as the neutral element for ``+``"
        Calling "1" the identity of the "+" operation, or calling "+" an operation
        having "1" as its identity element is, errr, uncommon at least, but
        perfectly valid...

        --
        Gabriel Genellina

        Comment

        • Russ P.

          #19
          Re: Avoiding local variable declarations?

          On Nov 17, 5:12 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
          wrote:
          En Mon, 17 Nov 2008 22:18:51 -0200, Steven D'Aprano
          <ste...@remove. this.cybersourc e.com.auescribi ó:
          >
          On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
          >
          Not such illogical crap like
          ``a = a + 1`` which must be obviously false unless 1 is defined as the
          neutral element for the definition of ``+`` here.
          >
          I don't quite know what you mean by "neutral element". I think you mean
          the identity element under addition, which is zero, but that doesn't
          work:
          >
          0 = 0 + 1
          >
          Obviously not.
          >
          Perhaps you didn't read carefully the above post? He said "unless *1* is
          defined as the neutral element for ``+``"
          Calling "1" the identity of the "+" operation, or calling "+" an operation
          having "1" as its identity element is, errr, uncommon at least, but
          perfectly valid...
          >
          --
          Gabriel Genellina
          def __add__(self, other): return self + other - 1

          Don't tell me this is not "Pythonic"!



          Comment

          • Steven D'Aprano

            #20
            Re: Avoiding local variable declarations?

            On Mon, 17 Nov 2008 23:12:25 -0200, Gabriel Genellina wrote:

            Perhaps you didn't read carefully the above post?
            Er, yes, you got me on that.

            :(


            --
            Steven

            Comment

            • Marc 'BlackJack' Rintsch

              #21
              Re: Avoiding local variable declarations?

              On Tue, 18 Nov 2008 00:18:51 +0000, Steven D'Aprano wrote:
              On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
              >
              >Not such illogical crap like
              >``a = a + 1`` which must be obviously false unless 1 is defined as the
              >neutral element for the definition of ``+`` here.
              >
              I don't quite know what you mean by "neutral element". I think you mean
              the identity element […]
              I knew I should have looked it up instead of "translatin g" it from my
              mother tongue -- yes I ment "identity element". Sorry for the confusion.

              Ciao,
              Marc 'BlackJack' Rintch

              Comment

              • Arnaud Delobelle

                #22
                Re: Avoiding local variable declarations?

                Marc 'BlackJack' Rintsch <bj_666@gmx.net writes:
                On Tue, 18 Nov 2008 00:18:51 +0000, Steven D'Aprano wrote:
                >
                >On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
                >>
                >>Not such illogical crap like
                >>``a = a + 1`` which must be obviously false unless 1 is defined as the
                >>neutral element for the definition of ``+`` here.
                >>
                >I don't quite know what you mean by "neutral element". I think you mean
                >the identity element […]
                >
                I knew I should have looked it up instead of "translatin g" it from my
                mother tongue -- yes I ment "identity element". Sorry for the confusion.
                >
                Neutral element is correct. But maybe its use is limited to
                mathematicians in the english-speaking word.

                --
                Arnaud

                Comment

                • Gabriel Genellina

                  #23
                  Re: Avoiding local variable declarations?

                  En Tue, 18 Nov 2008 16:27:46 -0200, Arnaud Delobelle
                  <arnodel@google mail.comescribi ó:
                  Marc 'BlackJack' Rintsch <bj_666@gmx.net writes:
                  >On Tue, 18 Nov 2008 00:18:51 +0000, Steven D'Aprano wrote:
                  >>On Mon, 17 Nov 2008 12:32:35 +0000, Marc 'BlackJack' Rintsch wrote:
                  >>>
                  >>>Not such illogical crap like
                  >>>``a = a + 1`` which must be obviously false unless 1 is defined as the
                  >>>neutral element for the definition of ``+`` here.
                  >>>
                  >>I don't quite know what you mean by "neutral element". I think you mean
                  >>the identity element […]
                  >I knew I should have looked it up instead of "translatin g" it from my
                  >mother tongue -- yes I ment "identity element". Sorry for the
                  >confusion.
                  Neutral element is correct. But maybe its use is limited to
                  mathematicians in the english-speaking word.
                  In Spanish I've seen "elemento neutro" and "elemento identidad" used
                  interchangeably .

                  --
                  Gabriel Genellina

                  Comment

                  • greg

                    #24
                    Re: Avoiding local variable declarations?

                    Arnaud Delobelle wrote:
                    Neutral element is correct. But maybe its use is limited to
                    mathematicians in the english-speaking word.
                    I've only ever seen "identity element" in English mathematics.
                    "Neutral element" sounds like something my car's gearbox
                    might have...

                    --
                    Greg

                    Comment

                    • Mark Wooding

                      #25
                      Re: Avoiding local variable declarations?

                      greg <greg@cosc.cant erbury.ac.nzwro te:
                      I've only ever seen "identity element" in English mathematics.
                      "Neutral element" sounds like something my car's gearbox
                      might have...
                      I've encountered both. I think `neutral element' is more common when
                      dealing with the possibility that it might not be unique (in the way
                      that identity elements are in groups, rings and fields), but that might
                      just be my misconception.

                      -- [mdw]

                      Comment

                      • Arnaud Delobelle

                        #26
                        Re: Avoiding local variable declarations?

                        greg <greg@cosc.cant erbury.ac.nzwri tes:
                        Arnaud Delobelle wrote:
                        >
                        >Neutral element is correct. But maybe its use is limited to
                        >mathematicia ns in the english-speaking word.
                        >
                        I've only ever seen "identity element" in English mathematics.
                        "Neutral element" sounds like something my car's gearbox
                        might have...
                        I was an academic mathematician for several years (although not a very
                        good one) and I can assure you that 'neutral element' is correct and
                        understood. 'Unit element' is another common synonym.

                        Unfortunately I can't find a reference in one of the few books in
                        English that I have at home. Lang's "Algebra" does not seem to use the
                        term and it's the only undergraduate book I've got. Wikipedia and other
                        internet sources cite 'neutral element' as a synonym to 'identity
                        element'.

                        --
                        Arnaud

                        Comment

                        Working...