Moritz (>), Solomon (>>), Moritz (>>>): >> > the current spec doesn't allow immutable containers to call .map with a >> > block that implicitly uses $_ as an implicit parameter. >> > >> > Here's why: >> > >> > S06 says >> > >> >> The C<$_> variable functions as a placeholder in a block without any >> >> other placeholders or signature. Any bare block without placeholders >> >> really has a parameter like this: >> >> >> >> -> $_ is rw = OUTER::<$_> { .mumble } >> > >> > So $_ is marked as rw, which is checked at binding time. >> > >> > Now lists are immutable, meaning that you can't bind a list item rw, so >> > even if the block doesn't try to modify $_, calling the { .say } block >> > fails. >> > >> > (Note that 'for' has the same problem) >> > >> > How should that be resolved? Should a temporary variable be created that >> > can be changed, without any effect? or should it fail() on detecting a >> > modification? Somehow this approach seems very backward to me... >> >> Is there a reason $_ is readonly isn't a possible solution? > > I have no idea how often $_ as an implicit parameter is actually used. > Note that if you want s/// to work, you really need a mutable $_. > > If it were just for iteration, I'd not object to making it an ro-alias by > default, requiring an explict rw signature (for example with <-> $_ { ... }) > otherwise.
That would make statement modifier for loops less useful. For those, there's nowhere to put the lambda arrow. ++$_ for @things; // Carl