News for hackers. Stuff that matters.
Re:Kotlin: A Language with a Bright Future by lmm on Monday November 20, 2017 @11:06AM (#15740882)
> In fact, the language designers even took care (for the sake of comprehensibility :) to ensure that the semantics of the two fors (in a two-level nested listcomp) have the same meaning (aka order of priority) as a two-level nested for loop, i.e. outer for wraps inner for, in both cases. It's mentioned in the spec somewhere.

Yeah, I think that was a huge mistake, because the most common case is one-level and if you have one level the syntax is just the reverse of a regular for, but in a two-level comprehension (the rare case) you have to remember that it's not a reversal, it's a cyclic permutation.

i.e. most of the examples you see look like this, and these two are equivalent:

    [y for i in x]
    for i in x: y
and then occasionally you see a comprehension that looks like:

    [z for j in y for i in x]
so you'd expect this to be equivalent to

    for i in x: for j in y: z
but it isn't, it's equivalent to

    for j in y: for i in x: z
which is really hard to remember.
Re:Kotlin: A Language with a Bright Future by vram22 on Wednesday November 22, 2017 @12:07PM (#15758388)
Hadn't thought of it that way myself, I may have just thought that the way (order) it works is the same as the way it is actually designed to work, and then later looking at the docs confirmed that, but yes, yours is a valid point of view.