ceylon / ceylon-spec

DEPRECATED
Apache License 2.0
108 stars 34 forks source link

disallow parameters in initial parameter lists to be declared in function block #1426

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

Correct behavior for:

shared Integer counter(first)() {
    variable Integer first;
    return first++;
}

shared void testCounter() {
    value c = counter(10);
    printAll { c(), c(), c() }; // 10, 10, 10
}

is hard to predict. Is first captured in the initial call to counter(10), or is it scoped where it is actually declared?

A possible solution would be to disallow declarations to be made in a function block for parameters that are not in the last parameter list.

gavinking commented 8 years ago

Fixed!

gavinking commented 8 years ago

I wonder if that fix was too heavy-handed. There would be no problem if it weren't variable.

jvasileff commented 8 years ago

I wonder if that fix was too heavy-handed.

Perhaps so. It sort of goes against the idea of using currying as a benefit to the caller without adding implementation complexity or decreasing readability.

This also happens to be a big reason why I think the error is so important for variables–since splitting parameter lists seems so harmless.

(I say that after fixing some experimental code I had with functions similar in nature to Iterable.fold()() where the fact that it's curried isn't very relevant to the impl.)

gavinking commented 8 years ago

Could be, but I don't want to touch this again for 1.2.