News for hackers. Stuff that matters.
Re:Coconut – Pythonic functional programming language by hexane360 on Thursday June 23, 2016 @10:37AM (#11961183)
I think a big thing for many is the lambda: syntax, as well as the lack of full anonymous functions.
Re:Coconut – Pythonic functional programming language by masklinn on Thursday June 23, 2016 @11:06AM (#11961493)
The latter can't really happen given Python is a statements- and indentations-based language. You'd need some really weird meta-magical syntax which really isn't going to happen in Python. Although you can cheat by fucking around with decorators e.g.

    def postfix(fn, *args):
        return lambda arg: fn(arg, *args)

    @postfix(map, range(5))
    def result(i):
        return i * i

    print result
    # [0, 1, 4, 9, 16]
(`postfix` is necessary because `map` takes its argument positionally so it's not possible to pass in the sequence with functools.partial)
Re:Coconut – Pythonic functional programming language by dragonwriter on Thursday June 23, 2016 @11:24AM (#11961676)
> The latter can't really happen given Python is a statements- and indentations-based language.

Yeah, though I suppose you could hack around that and get nearly-full functionality in lambdas if you built a library that either wrapped non-expression statements in functions or provided equivalent functions. There are obviously some statements that there aren't good solutions for in that direction.

OTOH, using named functions is in many cases more readable -- in the context of what is otherwise a normal Python codebase -- than the kind of lambdas that you can't easily write in Python. But I like the Coconut approach of but providing a more concise syntax for the kind of lambdas Python already supports.

Re:Coconut – Pythonic functional programming language by NegativeLatency on Thursday June 23, 2016 @11:05AM (#11961481)
I agree that typing out the word lambda is annoying, but you can use them as fully anonymous functions.
Re:Coconut – Pythonic functional programming language by masklinn on Thursday June 23, 2016 @11:07AM (#11961502)
> you can use them as fully anonymous functions.

A lambda can only contain a single expression, by "full anonymous function" I'm guessing hexane360 means multiple statements. You can't put a for loop or a context manager in a lambda for instance.

Re:Coconut – Pythonic functional programming language by grondilu on Thursday June 23, 2016 @11:25AM (#11961693)
You can nest lambdas to get the equivalent of several expressions. I once wrote a Runge-Kutta example on Rosetta Code showing this:

http://rosettacode.org/wiki/Runge-Kutta_method#using_lambda

It does not look as bad as one might expect, though the nesting of parenthesis makes things messy.

Re:Coconut – Pythonic functional programming language by masklinn on Thursday June 23, 2016 @11:35AM (#11961796)
You can but you still can't get statements in there.
Re:Coconut – Pythonic functional programming language by ergl on Thursday June 23, 2016 @12:07PM (#11962063)
You can hack together multiple expressions chaining them with and http://sigusr2.net/one-line-echo-server-using-let-python.htm...
Re:Coconut – Pythonic functional programming language by zardeh on Thursday June 23, 2016 @01:21PM (#11962745)
That still doesn't get you statements.

You can't get context managers or exception handling (although you can raise exceptions) into lambdas, I've tried.

Re:Coconut – Pythonic functional programming language by masklinn on Thursday June 23, 2016 @01:35PM (#11962870)
Well you might be able to if you add a bunch of named function combinators wrapping these, but definitely not with only lambdas, unless you define your combinators using `ast`, which I think would let you define statements via expressions.
Re:Coconut – Pythonic functional programming language by AnkhMorporkian on Thursday June 23, 2016 @03:18PM (#11963663)
That's an awful lot of effort to go to to avoid naming a function.
Re:Coconut – Pythonic functional programming language by zardeh on Friday June 24, 2016 @12:58PM (#11971444)
Well sure, you could do something like

    def apply_ctx(ctx, func, *func_args, **func_kwargs):
        with ctx as __ctx:
            func(*func_args, **func_kwargs, ctx=__ctx)
but you can't do that itself as a lambda. And I consider modifying the ast cheating :P
Re:Coconut – Pythonic functional programming language by masklinn on Friday June 24, 2016 @03:11PM (#11972561)
> but you can't do that itself as a lambda. And I consider modifying the ast cheating :P

No disagreement, really depends whether you're a "rules" or "spirit" kind of person though.