chromatic wrote:
> On Mon, 2005-06-13 at 17:07 +0200, Ingo Blechschmidt wrote:
>>   # No problem:
>>   my $data = BEGIN {
>>     my $fh = open "some_file" err...;
>>     =$fh;
>>   };
>>   # Problem;
>>   my $fh = BEGIN { open "some_file" err... };
>>   # Compile-time filehandle leaked into runtime!
>>   say =$fh;
> Perhaps I'm being very naive, but why is this a problem?  Maybe it's
> not the best way to do something, but I can see it being useful in
> some circumstances.

sorry I was unclear, the problem is:

Consider you want to first compile a program to a .pbc on host1, and
then run it on host2:

  host1 $ echo hi > some_file              # Make sure "some_file"
                                           # exists on host1.
  host1 $ cat > program.p6
  my $fh = BEGIN { open "some_file" err... };
  say =$fh
  host1 $ pugs -o program.pbc program.p6   # Hypothetical syntax
  # "some_file" is opened at compile-time, and an IO handle object
  # is returned. $fh contains an IO object now.
  # In the resulting program.pbc, there's no call to open() [1].
  host1 $ scp program.pbc host2:.          # Copy program.pbc to host2

  # "some_file" does not exist on host2:
  host2 $ ls -l some_file
  ls: some_file: No such file or directory
  host2 $ parrot program.pbc
  # XXX! Tries to readline() from an invalid filehandle!
  # Additionally, "some_file" doesn't exist on host2...

Do you see the problem? IO objects are only valid in the same process.
But the compiler process and the execution process are/may be
decoupled, or may even be on different computers.


[1] Similar as in this example:
      my $compiled_at = BEGIN { time };
      say "I was compiled at $compiled_at seconds after the epoch.";
    If you compile this to a .pbc, there won't be a call to time(),
    but the whole BEGIN block is substituted by the return value of
    time(). So, what the Perl 6 compiler will actually compile to
    PIR is:
      my $compiled_at = 172001560.613011;
      say "I was compiled at $compiled_at seconds after the epoch.";
    (Of course, a smart compiler can optimize this further.)

Linux, the choice of a GNU | To understand recursion, you must first
generation on a dual AMD   | understand recursion.
Athlon!                    | 

Reply via email to