develooper Front page | perl.perl6.language | Postings from March 2005

Re: [Pugs] Closing a file handle surprised the heck out of me

Thread Previous | Thread Next
From:
Luke Palmer
Date:
March 14, 2005 08:50
Subject:
Re: [Pugs] Closing a file handle surprised the heck out of me
Message ID:
20050314165206.GA1727@navi.cx
Autrijus Tang writes:
> On Mon, Mar 14, 2005 at 08:06:08AM -0800, Larry Wall wrote:
> > On Mon, Mar 14, 2005 at 10:58:00PM +1100, Andrew Savige wrote:
> > : my $fh = open(@ARGS[0]);
> > : my @lines = =$fh;
> > : $fh.close();
> > : for @lines { print"$_" }
> > : 
> > 
> > Hmm.  It's probably a design bug.  I'm wondering if we have to specify
> > that ordinary assignment not only copies logically but, in fact, always
> > does ** flattening (immediate flattening) like Perl 5
> 
> Except ** does not flatten recursively, so:
> 
>     my $lines = [ =$fh ];
> 
> is still borked.
> 
> Do we want a *** "nuke everything flat" semantic device, if not the
> operator?  Or an eager context on the right hand side of "="?
> 
> On the other hand, we can alternatively specify that closing a
> file handle must force all thunks associated to it, i.e. in this
> case fill @lines with real data.  Pugs can do that just fine, but I
> have no idea how parrot is to achieve that...

Perhaps lists by assignment are COW lazy.  So they behave just like
ordinary COW objects, except they can be lazy at the end:

    my @a = gather {
                for 1... {
                    say;
                    take;
                }
            };
    @a[10];  # says 1 2 3 ... 10
    @a[5] = 42;
    @a[20];  # nothing printed

I wonder if that's DingTRT though...

Luke

> 
> Thanks,
> /Autrijus/



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About