On Mon, Nov 2, 2009 at 2:03 PM, Solomon Foster <colo...@gmail.com> wrote: > On Mon, Nov 2, 2009 at 10:21 AM, Carl Mäsak <cma...@gmail.com> wrote: >> 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? >> >> For one thing, then you couldn't do this: >> >> my @a = 1, 2, 3; >> for @a { >> ++$_; >> } > > I meant, make it readonly if the container being iterated over is > readonly. We're working hard to make the language prefer immutable > things, it seems very odd to short circuit that in a key area like > this... > > (Though personally, I would prefer it if map was readonly by default > on all containers.)
Or Larry could just find an elegant way to do it. Yay! -- Solomon Foster: colo...@gmail.com HarmonyWare, Inc: http://www.harmonyware.com