←back to thread

317 points est | 1 comments | | HN request time: 0.233s | source
Show context
amelius ◴[] No.17448876[source]
If they add anything to Python, it should be the ability to do functional-style programming without hassle. Right now it's almost impossible to compose functions in an inline style such as used in functional programming languages. Yes, there's lambda, but it doesn't extend into multiple lines, and applying a function to a bunch of lambdas directly leads to line-width overflow. Even JavaScript has better support for functional-style programming. Perhaps Guido should spend a year writing Haskell :)
replies(8): >>17448904 #>>17448927 #>>17448972 #>>17449048 #>>17449482 #>>17450517 #>>17450691 #>>17451251 #
bjoli ◴[] No.17449048[source]
I wonder what would break if they started treating if as an expression. It is much nicer to do:

    def foo(X):
        if bar(foo):
            1
            False
replies(3): >>17449102 #>>17449137 #>>17450511 #
codetrotter ◴[] No.17449102[source]
I don’t understand what you are trying to write.

First of all you have indented 1 and False equally. Is that a typo? Or is it your opinion that the if should always consist of the if and the else branch without using the else keyword?

Secondly, if you want to return a value you need to use the return statement.

Also you wrote bar(foo) but foo was the name of the function, not the name of your parameter.

Perhaps what you are looking for is this:

    def foo(x):
        return 1 if bar(x) else False
replies(1): >>17449279 #
i_do_not_agree ◴[] No.17449279[source]
Perhaps s/he was looking at Lisp/Scheme:

  (define (foo x)
    (if (bar x)
      1
      #f))
The returned value is the value of the last expression. No need for an else, or a return keyword.
replies(2): >>17449565 #>>17452255 #
1. bjoli ◴[] No.17452255[source]
Thhis was exactly what I was trying to write, but wasn't able to switch to python mode on my phone :)