News for hackers. Stuff that matters.
Re:Python's Type Checking Renaissance by high_density on Tuesday January 26, 2021 @11:22AM (#25917622)
well there are some warts...

1. no multiline lambda function? - breaks flow of writing fp code

2. default-arguments are 'shared' by default? - have to 'break' this sharing by assigning 'None'... - very unintuitive / I don't know any language that does this...

Anyway, not everything in python is 'pragmatic', and adding types is one of the first steps in going in the right direction.

Re:Python's Type Checking Renaissance by urxvtcd on Tuesday January 26, 2021 @11:53AM (#25918075)
No multiline lambda is a feature. It is convenient enough to use it like in

    sort(items, key=lambda x: x.size)
but really anything much bigger should have a name stamped on it dammit. I find JS largely unintelligible due to lambda overuse and nesting.
Re:Python's Type Checking Renaissance by high_density on Tuesday January 26, 2021 @12:13PM (#25918409)
no it's not -- every other languages other than JS/TS has multiline lambdas... Java 8+, Kotlin, Rust, Scala, C#, ...

seems you're confused between "limitation" and "feature"...

it's a limitation due to python's "no-braces/indentations-only" policy -- can't think of a way to mark where a lambda starts and ends clearly and cleanly with indentation-only...

Re:Python's Type Checking Renaissance by joshuamorton on Tuesday January 26, 2021 @01:28PM (#25919413)
Disallowing multiline-lambdas was an intentional choice by the creators to prevent overly-functional code. For the same reasons that map/filter/reduce aren't in the global namespace anymore.

Python prefers different tools (comprehensions) to accomplish most of the same goals.

Re:Python's Type Checking Renaissance by urxvtcd on Tuesday January 26, 2021 @12:25PM (#25918593)
I mean, yeah, maybe that's the reason, I don't know. Still, I see no reason why you'd split features and limitations into two distinct sets.

In Rust it's difficult to mess with memory: it's a limitation but also a feature. In Haskell you cannot mutate, a limitation if there ever was one, but also a feature.

Re:Python's Type Checking Renaissance by high_density on Tuesday January 26, 2021 @01:54PM (#25919713)
woah another rustacean? hi there!

for rust, it counts as a 'feature' because it provides safety guarantee, and they're opt-in (can use unsafe)

as for haskell, that immutability also provides guarantee of 'referential-transparency', which the users/libraries can use to their advantange.

But in python's case, you have to define the multi-line function *outside* the chaining, and 'forcing to name things' isn't always good (especially for constantly-changing code)

def hideEmail(user): return { ...user, email: user.hideEmail? '': user.email, }

users.map(hideEmail)

// later: def hideEmailAndPhone(user): return { ...user, email: user.hideEmail? '': user.email, phoneNo: ... // same stuff }

users.map(hideEmailAndPhone) ---

As for JS/TS, you can have 'named-callback-fn':

users.map(function hidePrivateFields(user) { ... })

and it's not difficult to come up with 'named-lambda-fn' standard

users.map(hidePrivateFields(user) => { ... })

Re:Python's Type Checking Renaissance by jmkr on Tuesday January 26, 2021 @01:18PM (#25919309)

    (lamada x:
      (x+x)
      /x)(n)
Will work, though in Python I usually just create an outside function and pass that in.

But yes, not everything in Python is nice for working with fp code. Using tuples, coming from Clojure, is painful. Things like returning exceptions for `StopIteration`is annoying. Mutability of lists outside of a lexical scope without using deepcopy. Though functools and itertools makes it more bearable.

But I also don't think types is the answer. I think something like Racket's contracts or Clojure's spec is closer to what I'd prefer. Gradual typing is nice though.

Re:Python's Type Checking Renaissance by mixmastamyk on Thursday February 04, 2021 @10:32PM (#26032777)
Lambada, the forbidden dance:

    (
         lambda x:
         x
         +
         x
    )(5)