Lamdba forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lsmith234@gmail.com

    #1

    Lamdba forms

    hi all, I am a python newbie. why functions created with lambda forms
    cannot contain statements?
    how to get unnamed function with statements?

  • Terry Reedy

    #2
    Re: Lamdba forms


    <lsmith234@gmai l.com> wrote in message
    news:1145492986 .738200.229690@ i39g2000cwa.goo glegroups.com.. .[color=blue]
    > hi all, I am a python newbie. why functions created with lambda forms
    > cannot contain statements?[/color]

    Because statement do not fit in expressions.
    [color=blue]
    > how to get unnamed function with statements?[/color]

    Can't.

    Many discussions in archives (which Google has).

    tjr



    Comment

    • Paddy

      #3
      Re: Lamdba forms

      To expand on the above, Python does not have statements in its lambda
      forms, but that does not stop pythoneers from getting the job done.

      I use a named function for that, but if you have an issue with that, it
      really is worth following Terry's advice as the subject has been
      tackled at great length before.

      - Cheers, Paddy.

      Comment

      • Ant

        #4
        Re: Lamdba forms

        Why does the function have to be unnamed? you can easly nest function
        definitions and refer to them. IIRC the lambda form is probably going
        to be removed at some point, as it is not needed:

        def outerfn():
        dostuff()
        def inner(x,y):
        out = (x^y)
        print out
        return out

        my_local_functi on = inner
        my_local_functi on(3,4)

        outerfn()

        Comment

        • Duncan Booth

          #5
          Re: Lamdba forms

          Ant wrote:
          [color=blue]
          > IIRC the lambda form is probably going
          > to be removed at some point, as it is not needed:[/color]

          You remember incorrectly.

          Comment

          • Ant

            #6
            Re: Lamdba forms

            No, I remembered correctly:

            but probably not until Python 3.0.

            Comment

            • Fredrik Lundh

              #7
              Re: Lamdba forms

              "Ant" wrote:
              [color=blue]
              > No, I remembered correctly:
              > http://www.artima.com/weblogs/viewpost.jsp?thread=98196
              > but probably not until Python 3.0.[/color]

              however,



              (one would have thought that someone might have added a note to
              the comments of the first post, but the most recent contributor to
              that thread is a mortgage spammer...)

              </F>



              Comment

              • Ant

                #8
                Re: Lamdba forms

                Fair enough. I've just found this as well, which implies that lambda
                isn't being killed off in 3.0:

                This PEP, previously known as PEP 3000, describes smaller scale changes and new features for which no separate PEP is written yet, all targeted for Python 3000.


                In particular:
                "Lambdas will have to be parenthesized [23]"

                Comment

                • Duncan Booth

                  #9
                  Re: Lamdba forms

                  Ant wrote:
                  [color=blue]
                  > Fair enough. I've just found this as well, which implies that lambda
                  > isn't being killed off in 3.0:
                  >
                  > http://www.python.org/dev/peps/pep-3100/
                  >
                  > In particular:
                  > "Lambdas will have to be parenthesized [23]"
                  >[/color]

                  Also: http://www.python.org/doc/essays/ppt...6/Py3kACCU.ppt
                  slide 14.

                  Comment

                  Working...