David Storrs writes:
> On Sat, Jul 03, 2004 at 01:02:34AM -0600, Luke Palmer wrote:
> 
> > But indeed there are cases where it is a problem:
> > 
> >     my $x = 2;
> >     sub mklist () {
> >         return map { 2 * $_ } 0..10;
> >     }
> > 
> >     my @list = mklist;
> >     say @list[0..4];   # 0 2 4 6 8
> >     $x = 1;
> >     say @list;         # 0 2 4 6 8 5 6 7 8 9 10
> > 
> > Which is assuredly different from what would happen if it were evaluated
> > non-lazily.
> 
> Did you mean the body of mklist to be: 
> 
>           return map { 2 * $x } 0..10;
> # Note:--------------------^^

Haha, whoops.  No, I meant it to be:

    return map { $x * $_ } 0..10;

Changes things a bit, then :-)

Luke

Reply via email to