Hacker News new | ask | show | jobs
by kerkeslager 2169 days ago
> There's a reason why no new languages have chosen 'lambda' for anonymous functions.

Beware of people who say "there's a reason" and then don't say what that reason is.

I suspect the reason in this case is that languages which use C-ish syntax it would make no senes to have lambda as a keyword. Python doesn't use C-ish syntax, so that reason doesn't apply.

> It's annoying to constantly turn iterators into lists.

So don't. Why are you constantly turning iterators into lists?

> There's no reason for a function to take a list and return an iterator,

Here are 5 reasons:

1. There are many cases where the iterator will never be evaluated, meaning you save O(n) time.

2. Even in cases where you evaluate the iterator, you'll often have performed many transformations upon that iterator. Forcing 5 transformations all at once means you have 1 loop instead of 5, meaning again you save O(n) time.

3. It encourages writing functional code, which doesn't depend on order of execution. (This is why Simon Peyton Jones says Haskell has lazy evaluation: it keeps them honest about side effects).

4. Explicit is better than implicit. Guessing that a user will want a list is a reasonable guess, but you're doing a lot of work based on that guess, and some percentage of the time you'll be wrong. It's better to do the minimum work necessary and let the user explicitly determine what type of result they want.

5. Consistent extensibility: map, zip, etc. take lots of iterable types. You could attempt to return the same iterable type as you receive, but then there isn't an easy way for users to use zip on user-defined types. It's better to call the type's __iter__ function and then just use that, as this allows users to define higher-order functions on their own types.

1 comments

Look, functors (and therefore monads as well) are closed under fmap. That should be the end of the story.
It's pretty bizarre to assert that structures made up by some mathematician in a void should be the basis of a programming language intended to solve real-world problems, especially in response to giving real-world reasons for why it is the way it is.