Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default __get_string method #387

Closed
p6rt opened this issue Nov 5, 2008 · 4 comments
Closed

default __get_string method #387

p6rt opened this issue Nov 5, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 5, 2008

Migrated from rt.perl.org#60350 (status was 'resolved')

Searchable as RT60350$

@p6rt
Copy link
Author

p6rt commented Nov 5, 2008

From @chrisdolan

If you "say $x" on an $x that is an instance of class Foo that lacks
stringification via __get_string(), then you get a crash with the
error "get_string() not implemented in class Foo".

I propose that Perl6Object get a fallback __get_string method that
returns simply the class name and a unique identifier (maybe a
pointer value). While unaesthetic, that fallback would prevent the
program from just crashing and (as a bonus) would reveal the class
name. This approach has precedent in Perl5, Java, and other languages.

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

From @pmichaud

On Tue, Nov 04, 2008 at 10​:28​:26PM -0800, Chris Dolan wrote​:

I propose that Perl6Object get a fallback __get_string method that
returns simply the class name and a unique identifier (maybe a
pointer value).

Now added in r32373. Here's an example​:

  $ cat x
  class Foo {
  method speak() { say 'hello' }
  }
 
  say Foo.new();
 
  $ ./parrot perl6.pbc x
  Foo<0xb73ac540>
  $

As an added bonus, per Synopsis 13 one can also define a
C<Str> method in a class to specify how it stringifies​:

  $ cat y
  class Bar {
  method Str() { return 'world' }
  }
 
  say "hello { Bar.new() }";
  $ ./parrot perl6.pbc x
  hello world
  $

Closing ticket. Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 6, 2008
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant