Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

2 views
Skip to first unread message

Andrew Savige

unread,
Mar 14, 2005, 6:58:00 AM3/14/05
to perl6-c...@perl.org
Given this Pugs program, t.p6:

my $fh = open(@ARGS[0]);
my @lines = =$fh;
$fh.close();
for @lines { print"$_" }

running:

pugs t.p6 t.p6

produces no output. Move $fh.close() to after the for
loop and all is well. Is this a bug?

/-\


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

Larry Wall

unread,
Mar 14, 2005, 11:06:08 AM3/14/05
to perl6-c...@perl.org, perl6-l...@perl.org
On Mon, Mar 14, 2005 at 10:58:00PM +1100, Andrew Savige wrote:
: Given this Pugs program, t.p6:

:
: my $fh = open(@ARGS[0]);
: my @lines = =$fh;
: $fh.close();
: for @lines { print"$_" }
:
: running:
:
: pugs t.p6 t.p6
:
: produces no output. Move $fh.close() to after the for
: loop and all is well. Is this a bug?

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, and you *must*
use := binding to get lazy flattening. That is probably the course
of sanity. Since assignment is the primary means of violating FP's
no-side-effect idea, it makes sense that assignment is also what tries
its hardest to work around the issue when the user requests a side
effect like assignment. For example,

@foo = 1...;

would be an outright error, detectable at compile time in this case, while

@foo := 1...;

is perfectly fine. But my coffee isn't ready yet this morning,
so I reserve the right to be wronger than usual.

[Followups directed by default to p6l.]

Larry

0 new messages