Skip Menu |
Report information
Id: 77026
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Misleading .perl of anonymous classes in Rakudo
Date: Thu, 5 Aug 2010 23:13:51 +0200
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 626b
<ash_> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; # that looks funny too... <p6eval> rakudo 19931f: OUTPUT«.new(a => 1)␤» <ash_> but i have no idea what is "right", just looks funny... * masak submits rakudobug <pmichaud> rakudo: my $a = class { has $a; }; say $a.perl; <p6eval> rakudo 19931f: OUTPUT«␤» On the principle that an eval should give you back what you started with, probably both of these are wrong. Might not be easy or even doable to get right, but we should probably avoid spitting out something that we know will be eval'd wrongly. Might even be better to die or fail in that case.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1000b
On Thu Aug 05 14:14:15 2010, masak wrote: Show quoted text
> <ash_> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; # > that looks funny too... > <p6eval> rakudo 19931f: OUTPUT«.new(a => 1)␤» > <ash_> but i have no idea what is "right", just looks funny... > * masak submits rakudobug > <pmichaud> rakudo: my $a = class { has $a; }; say $a.perl; > <p6eval> rakudo 19931f: OUTPUT«␤» > > On the principle that an eval should give you back what you started > with, probably both of these are wrong. Might not be easy or even > doable to get right, but we should probably avoid spitting out > something that we know will be eval'd wrongly. Might even be better to > die or fail in that case.
These now output: 20:47 < [Coke]> rakudo: my $a = class { has $a; }; say $a.perl; 20:47 <+p6eval> rakudo 545638: OUTPUT«<anon>␤» 20:47 < [Coke]> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; 20:47 <+p6eval> rakudo 545638: OUTPUT«<anon><-856690017062603138>␤» -- Will "Coke" Coleda
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Tue Oct 04 17:48:14 2011, coke wrote: Show quoted text
> On Thu Aug 05 14:14:15 2010, masak wrote:
> > <ash_> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; # > > that looks funny too... > > <p6eval> rakudo 19931f: OUTPUT«.new(a => 1)␤» > > <ash_> but i have no idea what is "right", just looks funny... > > * masak submits rakudobug > > <pmichaud> rakudo: my $a = class { has $a; }; say $a.perl; > > <p6eval> rakudo 19931f: OUTPUT«␤» > > > > On the principle that an eval should give you back what you started > > with, probably both of these are wrong. Might not be easy or even > > doable to get right, but we should probably avoid spitting out > > something that we know will be eval'd wrongly. Might even be better to > > die or fail in that case.
> > These now output: > > 20:47 < [Coke]> rakudo: my $a = class { has $a; }; say $a.perl; > 20:47 <+p6eval> rakudo 545638: OUTPUT«<anon>␤» > 20:47 < [Coke]> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; > 20:47 <+p6eval> rakudo 545638: OUTPUT«<anon><-856690017062603138>␤»
Slight change: 01:21 <[Coke]> rakudo: my $a = class { has $a; }; say $a.perl; 01:21 <camelia> rakudo bfd850: OUTPUT«<anon>␤» 01:21 <[Coke]> rakudo: my $a = class { has $a; }; say $a.new(a => 1).perl; 01:21 <camelia> rakudo bfd850: OUTPUT«<anon>.new()␤» -- Will "Coke" Coleda
Download (untitled) / with headers
text/plain 269b
Slightly different output now: <Zoffix> m: my $a = class { has $a; }; say $a.perl; <camelia> rakudo-moar d075c8: OUTPUT«<anon|56051152>␤» <Zoffix> m: my $a = class { has $a; }; say $a.new(a => 1).perl; <camelia> rakudo-moar d075c8: OUTPUT«<anon|65422928>.new␤»
On Mon Jul 11 17:20:58 2016, cpan@zoffix.com wrote: Show quoted text
> Slightly different output now: > > <Zoffix> m: my $a = class { has $a; }; say $a.perl; > <camelia> rakudo-moar d075c8: OUTPUT«<anon|56051152>␤» > <Zoffix> m: my $a = class { has $a; }; say $a.new(a => 1).perl; > <camelia> rakudo-moar d075c8: OUTPUT«<anon|65422928>.new␤»
With $.a instead of $a: perl6 -e 'my $a = class { has $.a }; say $a.new.perl;' <anon|61557440>.new(a => Any) perl6 -e 'my $a = class { has $.a }; say $a.new(a => 1).perl;' <anon|70970080>.new(a => 1) perl6 --version This is Rakudo version 2016.08.1-59-gec9e814 built on MoarVM version 2016.08-23-gfa9528b implementing Perl 6.c. The equivalent output with a named class: perl6 -e 'class A { has $.a }; say A.new(a => 1).perl;' A.new(a => 1) perl6 -e 'class A { has $.a }; say A.new.perl;' A.new(a => Any) perl6 -e 'class A { has $a }; say A.new(a => 1).perl;' A.new perl6 -e 'class A { has $a }; say A.new.perl;' A.new I'm not sure what would be better than the current behavior for anonymous classes. Maybe 'class { has $.a }.new' or 'class { has $.a }.new(a => 1)'?
Download (untitled) / with headers
text/plain 3.3k
On Wed, 31 Aug 2016 19:06:13 -0700, ddgreen@gmail.com wrote: Show quoted text
> On Mon Jul 11 17:20:58 2016, cpan@zoffix.com wrote:
> > Slightly different output now: > > > > <Zoffix> m: my $a = class { has $a; }; say $a.perl; > > <camelia> rakudo-moar d075c8: OUTPUT«<anon|56051152>␤» > > <Zoffix> m: my $a = class { has $a; }; say $a.new(a => 1).perl; > > <camelia> rakudo-moar d075c8: OUTPUT«<anon|65422928>.new␤»
> > > With $.a instead of $a: > > perl6 -e 'my $a = class { has $.a }; say $a.new.perl;' > <anon|61557440>.new(a => Any) > > perl6 -e 'my $a = class { has $.a }; say $a.new(a => 1).perl;' > <anon|70970080>.new(a => 1) > > perl6 --version > This is Rakudo version 2016.08.1-59-gec9e814 built on MoarVM version > 2016.08-23-gfa9528b > implementing Perl 6.c. > > > The equivalent output with a named class: > > perl6 -e 'class A { has $.a }; say A.new(a => 1).perl;' > A.new(a => 1) > > perl6 -e 'class A { has $.a }; say A.new.perl;' > A.new(a => Any) > > perl6 -e 'class A { has $a }; say A.new(a => 1).perl;' > A.new > > perl6 -e 'class A { has $a }; say A.new.perl;' > A.new > > > I'm not sure what would be better than the current behavior for > anonymous classes. > Maybe 'class { has $.a }.new' or 'class { has $.a }.new(a => 1)'?
Some discussion on #perl6-dev, https://irclog.perlgeek.de/perl6-dev/2017-03-05#i_14208515 [09:22] <MasterDuke> m: my $a = class { has $.b }; say $a.new(b => 1).perl; [09:22] <+camelia> rakudo-moar d04c47: OUTPUT: «<anon|65402160>.new(b => 1)␤» [09:24] <MasterDuke> would `class { has $.a }.new(a => 1)` be a better output in that ^^^ case? [09:24] <MasterDuke> * s/a/b/g [09:24] <moritz> better, yes [09:25] <moritz> but certainly not perfect, because it might reference outer lexical symbols [09:25] <MasterDuke> well, that's true for any .perl, right? [09:25] <moritz> m: my $x = do { class A { has $.x }; class :: is B { has $.y }.new(x => 1, y => 2) }; say $x.perl [09:25] <+camelia> rakudo-moar d04c47: OUTPUT: «===SORRY!=== Error while compiling <tmp>␤'<anon|49526768>' cannot inherit from 'B' because it is unknown.␤at <tmp>:1␤» [09:26] <moritz> m: my $x = do { class A { has $.x }; class :: is A { has $.y }.new(x => 1, y => 2) }; say $x.perl [09:26] <+camelia> rakudo-moar d04c47: OUTPUT: «<anon|69579408>.new(y => 2, x => 1)␤» [09:26] <MasterDuke> m: my $a = class A { has $.b }; say $a.new(b => 1).perl; [09:26] <+camelia> rakudo-moar d04c47: OUTPUT: «A.new(b => 1)␤» [09:26] <MasterDuke> i was just comparing it to ^^^ [09:26] <moritz> yes [09:26] <moritz> and you're right, .perl typically reference a symbol which must be in scope to work [09:27] <MasterDuke> and fyi, i'm asking for https://rt.perl.org/Ticket/Display.html?id=77026 [09:28] <nine> Given module A which requires module B. Should after "require A;" B be available through indirect lookup? [09:28] <IOninja> m: my $x = class {}; my @a = $x, $x; @a.perl.say [09:28] <+camelia> rakudo-moar d04c47: OUTPUT: «[<anon|50504976>, <anon|50504976>]␤» [09:28] <IOninja> MasterDuke: ^ in your version, those two will be different classes too [09:31] <MasterDuke> ah. could do something like `class <anon|50504976> { has $.a }.new(a => 1)`? [09:31] <IOninja> Don't really know how you're going to retrieve the guts either. [09:32] <IOninja> If you're just sticking public attributes into a `class {}`, it's really just as useless as <anon|432423432> thing we currently have


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org