To do inline comprehension or not? #123
paul-hammant
started this conversation in
General
Replies: 2 comments
|
Exactly right; map, filter, and filter_map as stdlib functions, not new syntax. The two-liner is perfectly readable and fits how Aether works. No need to chase one-liner comprehensions. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hypothesis:
Open question; How would we do:
And that with a comment "I guess it comes down to what is small enough a language and what is left out. Go rejects the functional style to my understanding or at least does not offer it in it's standard library, because the language wants to
be small. Aether to my understanding does not want to be that small, or has just a different flavour."
Thoughts on that last
The Go code is a filter-then-map: keep even numbers, square them. In Aether with list.map and list.filter:
That's clean but it's two passes and an intermediate list. The Go version does it in one pass. To match that, you'd want a list.filter_map that does both:
But that's getting awkward as the null sentinel for "skip this element" is ugly.
The honest answer for the maintainer: Aether's trailing block style doesn't naturally compress to one-liners the way Python comprehensions do. And that's fine. The Go code is 5 lines and perfectly readable. The Aether version is 2 lines and also readable. Trying to force it into 1 line fights the language's block-based nature.
The real question is whether list.map and list.filter earn their place as stdlib functions. I'd say yes - they're the most common list operations after iteration, they compose naturally with trailing blocks (which is Aether's signature), and they're about 20 lines of C each. They don't make the language bigger - they're library functions, not syntax.
More linguistic framing:
All reactions