Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-17 Thread Moritz Lenz
On 07/13/2011 10:00 PM, Parrot Raiser wrote:
> The following program:
> 
> my $skeleton = "bones\n";
> my $new_file = "grave";
> my $handle   = open($new_file, :w);
> $handle.print($skeleton);
> 
> opens the "grave" file, but leaves it empty. A last line:
> 
> close($handle);# "close()" generates an error message.
> 
> is required to get any contents in the file, unlike the equivalent Perl 5 
> code:

That's because Rakudo isn't yet able to execute any code (like a DESTROY
method in Perl 5) when the garbage collector detects that an object is
not referenced anywhere anymore. So it's a limitation in Rakudo, not a
change in the language.

An intrinsic difference is that Perl 5 guarantees a timely execution of
such methods (because it is reference counted), whereas Perl 6 does not.

Question to the Parrot developers: How could I implement DESTROY methods
in Rakudo? Is there any vtable I can override, or so? Note that such a
method might itself allocate new GCables. While not urgent, it's
important for us in the long run.

Cheers,
Moritz


Re: Bug?

2011-07-17 Thread Moritz Lenz

On 07/14/2011 11:47 PM, Parrot Raiser wrote:
> When a subroutine is invoked with an empty parameter list, as follows:
> 
> run_stuff();
> 
> sub run_stuff {
> my ($parm) = @_;
> say "Parameter is $parm";
> }
> 
> @_[0] contains "Any()".

Not "Any()", but Any (which say() prints as "Any()" to ease debugging)

> Should it?

Yes.


Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-17 Thread Patrick R. Michaud
On Sun, Jul 17, 2011 at 10:21:19AM +0200, Moritz Lenz wrote:
> 
> Question to the Parrot developers: How could I implement DESTROY methods
> in Rakudo? Is there any vtable I can override, or so? Note that such a
> method might itself allocate new GCables. While not urgent, it's
> important for us in the long run.

A possibly related (and more relevant) question for Parrot devs:
is there any reason that FileHandle PMCs do not automatically 
flush + close on destruction?

pmichaud@kiwi:~/nom$ cat fh.pir
.sub 'main' :main
$P0 = new ['FileHandle']
$P1 = $P0.'open'('test.txt', 'w')
$P1.'print'("Hello\n")
.end

pmichaud@kiwi:~/nom$ install/bin/parrot fh.pir
pmichaud@kiwi:~/nom$ cat test.txt
pmichaud@kiwi:~/nom$ ls -l test.txt
-rw-r--r-- 1 pmichaud pmichaud 0 2011-07-17 09:57 test.txt

Pm


Re: Bug?

2011-07-17 Thread Patrick R. Michaud
On Sun, Jul 17, 2011 at 10:40:01AM +0200, Moritz Lenz wrote:
> On 07/14/2011 11:47 PM, Parrot Raiser wrote:
> > When a subroutine is invoked with an empty parameter list, as follows:
> > 
> > run_stuff();
> > 
> > sub run_stuff {
> > my ($parm) = @_;
> > say "Parameter is $parm";
> > }
> > 
> > @_[0] contains "Any()".
> 
> Not "Any()", but Any (which say() prints as "Any()" to ease debugging)
> 
> > Should it?
> 
> Yes.

Not exactly -- master gets this wrong.  Type objects are supposed
to stringify to "" and produce a warning.

Nom (cf0da7d) also gets this somewhat wrong at present (but still better 
than master); it's treating the assignment as an item assignment.

Pm


Re: Bug?

2011-07-17 Thread Bruce Gray


On Jul 14, 2011, at 4:47 PM, Parrot Raiser wrote:


When a subroutine is invoked with an empty parameter list, as follows:

run_stuff();

sub run_stuff {
  my ($parm) = @_;
  say "Parameter is $parm";
}

@_[0] contains "Any()".

Should it?


Yes, but only because of the way you are inspecting it.

When run_stuff is called with no arguments, @_ is empty.
It does *not* contain an element with the value Any; it contains no  
elements at all.


When you ask for the value of a specific (and non-existent) element of  
the array,

you only see that the element has no defined value yet.
(The `Any` value in Perl 6 is like the `undef` value in Perl 5.)
The same will happen if you declared @foo, then asked for the value of  
@foo[42].



perl -MData::Dumper -e 'sub look { print Dumper scalar(@_), \@_,  
$_[0]; } look();'

   $VAR1 = 0;
   $VAR2 = [];
   $VAR3 = undef;
perl6 -e 'sub look { .say for @_.elems, @_.perl, @_[0].perl; }; look();'
   0
   []
   Any

--
Hope this helps,
Bruce Gray (Util)