Re: Known Bug in Rakudo?

2008-11-05 Thread Patrick R. Michaud
On Thu, Oct 30, 2008 at 08:03:17AM -0700, Ovid wrote:
 This code:
 
   class Point {
   has $.x is rw;
   has $.y is rw;
 
   method get_string () {
   return $.x, $.y;
   }
   }
 
   my Point $point .= new( :x1.2, :y-3.7 );
   say $point.x;
   say $point;
 
 Generates this output:
 
   1.2
   get_string() not implemented in class 'Point'

Now fixed in r32373.  The get_string() not implemented ...
message actually comes from Parrot -- in Perl 6 we define
stringification using the CStr method (see S13):

  $ cat point.pl
  class Point {
  has $.x is rw;
  has $.y is rw;
  
  method Str() {
  return $.x, $.y;
  }
  }
  
  my Point $point .= new( :x1.2, :y-3.7 );
  say $point.x;
  say $point;
  
  $ ./parrot perl6.pbc point.pl
  1.2
  1.2, -3.7
  $

This problem was also addressed in RT #60350 (now resolved).

Hope this helps, and thanks!

Pm


Re: Known Bug in Rakudo?

2008-10-30 Thread Moritz Lenz
Ovid wrote:
 This code:
 
   class Point {
   has $.x is rw;
   has $.y is rw;
 
   method get_string () {

The correct way to define user-defined stringfication is either through

method Str { ... }

or

method prefix:~ ($self: ) { ... }

(afaict both are not implemented in Rakudo yet)

Parrots concept of 'get_string' is on a different level (vtable stuff I
think, but I don't grok the internals) and not accessible from Perl 6.

   return $.x, $.y;
   }
   }
 
   my Point $point .= new( :x1.2, :y-3.7 );
   say $point.x;
   say $point;
 
 Generates this output:
 
   1.2
   get_string() not implemented in class 'Point'

I think that every class should have a default stringification. Dunno if
there's a ticket for it yet.

Cheers,
Moritz

-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/


Re: Known Bug in Rakudo?

2008-10-30 Thread Mark J. Reed
On Thu, Oct 30, 2008 at 12:46 PM, Moritz Lenz
[EMAIL PROTECTED] wrote:
 The correct way to define user-defined stringfication is either through

 method Str { ... }

 or

 method prefix:~ ($self: ) { ... }

 (afaict both are not implemented in Rakudo yet)

Yeah, I can't even declare a method that way (prefix:~), regardless
of whether or not Rakudo tries to call it to stringify.  The $self:
isn't needed in this case, though, right?  The body of the method just
uses $.x and $.y without going through a ref to the object.

As a point of comparison, Pugs accepts the operator overload
definition but doesn't honor it;  ~$point still returns the generic
obj:Point.

-- 
Mark J. Reed [EMAIL PROTECTED]


Re: Known Bug in Rakudo?

2008-10-30 Thread Patrick R. Michaud
On Thu, Oct 30, 2008 at 05:46:11PM +0100, Moritz Lenz wrote:
 
 I think that every class should have a default stringification. Dunno if
 there's a ticket for it yet.

I don't think there's a _spec_ for a default stringification yet.  
So we should probably propose that first, and then see about an 
implementation.  :-)

Pm


Re: Known Bug in Rakudo?

2008-10-30 Thread Moritz Lenz
Patrick R. Michaud wrote:
 On Thu, Oct 30, 2008 at 05:46:11PM +0100, Moritz Lenz wrote:
 
 I think that every class should have a default stringification. Dunno if
 there's a ticket for it yet.
 
 I don't think there's a _spec_ for a default stringification yet.  
 So we should probably propose that first, and then see about an 
 implementation.  :-)

$ perl5.10.0 -E 'say bless []'
main=ARRAY(0x8c56880)

If it's not specced in Perl 6, Perl 5 behaviour is used...

Actually I think that the idea of printing a class name (or anon or
something like that for anonymous classes) and a pointer address isn't
all that bad, because it gives some basic information, and reminds the
programmer that he either shouldn't print it, or define an overload method.

A fatal error seem too strong to me...

Anyway, a spec would still be nice.

Moritz


-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/