in reply to Re^3: "when" and replacements
in thread "when" and replacements

"least surprise" is a powerful consideration.

In Perl 6, you can declare the iteration variable of the for to have the desired attributes. For a given you could use an expression to cause a copy to be made: given (0+$x) {... and if you write a function that just returns its argument, and you call that function copy, then you could write given (copy $x) ... nice and sugary. It would be harder to impose aliasing if the normal case didn't.

But since it's been this way for a while now, I think any "fix" will be to use a pragma to choose the behavior.

Replies are listed 'Best First'.
Re^5: "when" and replacements
by JavaFan (Canon) on May 08, 2011 at 11:09 UTC
    "least surprise" is a powerful consideration.
    Then, IMO, it should not do aliasing. Aliasing (in for/foreach/map/grep/values) still surprises people, and it causes bugs. Except for the few 1000s of people who are really, really into Perl, most programmers don't know about aliases, and it will catch them off-guard.

    As for given, it will take a long time before given is used by "the masses" (that is, the 995,000 Perl programmers that aren't deeply connected to it). Most of them will never make the connection that given shares features with for. Even if they know about aliasing in for/foreach, I very much doubt they'll be surprised if given doesn't have it.

Re^5: "when" and replacements
by LanX (Saint) on May 08, 2011 at 12:58 UTC
    After some meditation I think this attempt to transplant Perl6 features with exactly the same syntax is the source of problems.

    Perl6 handles some fundamental stuffs like sigils differently and I'm not sure if its possible within P6 to use "when"-clauses within "foreach"-blocks.

    IMHO enforcing every detail leads to anti reactions in the perl5 system. I'd rather prefer a semantical correspondence of features than introducing more breaks in symmetry and logical confusion.

    For example nobody seems to care that c-style "for" is now "loop" in Perl6...same semantic but different syntax.

    Cheers Rolf