Re:Coconut – Pythonic functional programming language
by fiatjaf on Thursday June 23, 2016 @02:40PM
(#11963388)
No, you can't, because lambdas.
[ Parent
| on HN ]
Re:Coconut – Pythonic functional programming language
by quietwhisper on Thursday June 23, 2016 @05:29PM
(#11964449)
I know (and bemoan) that lambdas can only have a single expression returned, but can't you just use a named function? (Not as nice, I agree, but doesn't put a hard limit on FP in python.)
Re:Coconut – Pythonic functional programming language
by kd0amg on Thursday June 23, 2016 @05:31PM
(#11964457)
And manually closure-convert everything too?
Re:Coconut – Pythonic functional programming language
by devishard on Thursday June 23, 2016 @06:16PM
(#11964702)
Python supports nested functions, so closure conversion isn't necessary.
Re:Coconut – Pythonic functional programming language
by Lambdanaut on Thursday June 23, 2016 @05:10PM
(#11964328)
Could you elaborate on that?
Re:Coconut – Pythonic functional programming language
by SwellJoe on Thursday June 23, 2016 @05:51PM
(#11964560)
Python lambda is somewhat limited, compared to lambda in some other languages. Guido isn't overly fond of lambda or other functional building blocks (and even planned to remove it from Python, before there was a sufficient outpouring of support for keeping it). http://www.artima.com/weblogs/viewpost.jsp?thread=98196
As I understand it, the primary limitation is that Python lambda only works with a single expression (I think it also has some weirdness regarding scope when calling functions?). I haven't poked seriously at Python since around about the time they were talking about removing it, so I probably have no idea what I'm talking about.
The idea is that generators and list comprehensions do the things most people do with lambdas in a more Pythonic way.
Re:Coconut – Pythonic functional programming language
by fovc on Thursday June 23, 2016 @09:05PM
(#11965512)
I think the scoping issues you're referring to were resolved a while ago (PEP 227) -- nowadays lambda scope rules are the same as named functions.
Re:Coconut – Pythonic functional programming language
by merlincorey on Thursday June 23, 2016 @05:29PM
(#11964447)
Python lambdas are explicitly artificially limited to a single expression. Python has statements which are not expressions, mostly control statements and looping constructs.
Re:Coconut – Pythonic functional programming language
by fovc on Thursday June 23, 2016 @09:06PM
(#11965517)
The syntax isn't the greatest, but you can get pretty far with Python's ternary expression. Generators in my experience remove the need for most loops. Where lambdas feel really subpar for me is the lack of 'let' and error-handling.
Re:Coconut – Pythonic functional programming language
by Phrodo_00 on Thursday June 23, 2016 @09:22PM
(#11965594)
While it IS a conscious decision to force lambdas to be a single expression, extending it to be able to be multiline would screw up with indentation being irrelevant inside of a function call too.