Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55098

Re: Functional Programming and python

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Functional Programming and python
Date 2013-09-30 18:36 +0000
Organization Norwich University
Message-ID <batulcFnd7eU1@mid.individual.net> (permalink)
References (1 earlier) <CAPM-O+w=wGf2ZxezQj5Mccrx_mDsgtxxKNtmL4GhDn_x3ty2Rw@mail.gmail.com> <mailman.170.1375562619.1251.python-list@python.org> <c45c6fe3-b79c-4d14-9c89-b462808d7e32@googlegroups.com> <ba94102b-18b6-4850-ac85-032b0fe2fa75@googlegroups.com> <nobody-C700FA.19043230092013@news.free.fr>

Show all headers | View raw


On 2013-09-30, Franck Ditter <nobody@nowhere.org> wrote:
> In article <ba94102b-18b6-4850-ac85-032b0fe2fa75@googlegroups.com>,
>  rusi <rustompmody@gmail.com> wrote:
>> I touched upon these in two blog-posts:
>> 1. http://blog.languager.org/2013/06/functional-programming-invades.html
>> 2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html
>> 
>> Also most programmers without an FP background have a poor
>> appreciation of the centrality of recursion in CS; see
>> http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html
>
> Good approach of FP in Python, but two points make me crazy :
> 1. Tail recursion is not optimized. We are in 2013, why ? This
> is known technology (since 1960). And don't answer with "good
> programmers don't use recursion", this is bullshit.

If you've got a set of recursive functions with recursive calls
in tail-call position it's pretty easy to convert to a solution
that doesn't blow the stack. Converting to a while loop is
usually straightforward, or you try trampolining.

If the calls aren't in tail-call position then you wouldn't get
tail-call optimization from a language like scheme, either.

Getting calls in tail position is often the sticking point, and
tail-call optimization doesn't help with that.

I think the Python rationale also discusses how it would make
tracebacks harder to understand if stackframes could clobber each
other. Personally I think that's more a theoretical than a
practical problem. Languages with tail-call optimization aren't
impossible to debug.

> 2. Lambda-expression body is limited to one expression. Why ?
> Why the hell those limitations ? In this aspect, Javascript has
> a cooler approach.

It's in the Design and History FAQ.

http://docs.python.org/3/faq/design.html

    Why can’t lambda forms contain statements?

    Python lambda forms cannot contain statements because
    Python’s syntactic framework can’t handle statements nested
    inside expressions. However, in Python, this is not a serious
    problem. Unlike lambda forms in other languages, where they
    add functionality, Python lambdas are only a shorthand
    notation if you’re too lazy to define a function.

    Functions are already first class objects in Python, and can
    be declared in a local scope. Therefore the only advantage of
    using a lambda form instead of a locally-defined function is
    that you don’t need to invent a name for the function – but
    that’s just a local variable to which the function object
    (which is exactly the same type of object that a lambda form
    yields) is assigned!

What I usually end up with is a dictionary of callbacks, with the
simple functions defined in-line and the more complex functions
defined just before that and referenced instead.

-- 
Neil Cerutti

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Where to suggest improvements in the official Python documentation? Aseem Bansal <asmbansal2@gmail.com> - 2013-08-03 10:53 -0700
  Re: Where to suggest improvements in the official Python documentation? Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-03 14:23 -0400
  Re: Where to suggest improvements in the official Python documentation? Terry Reedy <tjreedy@udel.edu> - 2013-08-03 16:43 -0400
    Re: Where to suggest improvements in the official Python documentation? Aseem Bansal <asmbansal2@gmail.com> - 2013-08-04 09:30 -0700
      Re: Where to suggest improvements in the official Python documentation? Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-04 14:34 -0400
        Re: Where to suggest improvements in the official Python documentation? Aseem Bansal <asmbansal2@gmail.com> - 2013-08-20 07:22 -0700
          Re: Where to suggest improvements in the official Python documentation? Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-20 10:57 -0400
      Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-22 19:21 -0700
        Re: Functional Programming and python Vito De Tullio <vito.detullio@gmail.com> - 2013-09-23 20:24 +0200
          Re: Functional Programming and python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-24 10:06 +0300
          Re: Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-24 00:08 -0700
            Re: Functional Programming and python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-24 10:42 +0300
              Re: Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-24 05:14 -0700
                Re: Functional Programming and python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-24 17:51 +0300
                Re: Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-24 08:07 -0700
                Re: Functional Programming and python Chris Angelico <rosuav@gmail.com> - 2013-09-25 01:26 +1000
                Re: Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-24 10:25 -0700
        Re: Functional Programming and python Franck Ditter <nobody@nowhere.org> - 2013-09-30 19:04 +0200
          Re: Functional Programming and python Chris Angelico <rosuav@gmail.com> - 2013-10-01 03:17 +1000
          Re: Functional Programming and python Neil Cerutti <neilc@norwich.edu> - 2013-09-30 18:36 +0000
            Re: Functional Programming and python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 00:14 +0000
              Re: Functional Programming and python Neil Cerutti <neilc@norwich.edu> - 2013-10-01 13:59 +0000
          Re: Functional Programming and python Piet van Oostrum <piet@vanoostrum.org> - 2013-09-30 14:55 -0400
            Re: Functional Programming and python Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-30 22:37 +0200
              Re: Functional Programming and python Piet van Oostrum <piet@vanoostrum.org> - 2013-10-01 13:31 -0400
          Re: Functional Programming and python Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-30 20:29 +0200
          Re: Functional Programming and python Tim Chase <python.list@tim.thechases.com> - 2013-09-30 16:02 -0500
          Re: Functional Programming and python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 00:41 +0000
          Re: Functional Programming and python alex23 <wuwei23@gmail.com> - 2013-10-01 11:03 +1000
          Re: Functional Programming and python Terry Reedy <tjreedy@udel.edu> - 2013-09-30 21:03 -0400
            Re: Functional Programming and python rusi <rustompmody@gmail.com> - 2013-09-30 18:36 -0700
              Re: Functional Programming and python Chris Angelico <rosuav@gmail.com> - 2013-10-01 17:28 +1000

csiph-web