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

Misleading .perl of anonymous classes in Rakudo #2022

Open
p6rt opened this issue Aug 5, 2010 · 10 comments
Open

Misleading .perl of anonymous classes in Rakudo #2022

p6rt opened this issue Aug 5, 2010 · 10 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 5, 2010

Migrated from rt.perl.org#77026 (status was 'open')

Searchable as RT77026$

@p6rt
Copy link
Author

p6rt commented Aug 5, 2010

From @masak

<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.

@p6rt
Copy link
Author

p6rt commented Oct 5, 2011

From @coke

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>␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 5, 2011

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

@p6rt
Copy link
Author

p6rt commented May 11, 2013

From @coke

On Tue Oct 04 17​:48​:14 2011, coke wrote​:

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

@p6rt
Copy link
Author

p6rt commented Jul 12, 2016

From @zoffixznet

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␤»

@p6rt
Copy link
Author

p6rt commented Sep 1, 2016

From @MasterDuke17

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)'?

@p6rt
Copy link
Author

p6rt commented Mar 5, 2017

From @MasterDuke17

On Wed, 31 Aug 2016 19​:06​:13 -0700, ddgreen@​gmail.com wrote​:

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-archive.perl.org/perl6/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

@p6rt p6rt added the Bug label Jan 5, 2020
@JJ
Copy link

JJ commented Dec 29, 2020

If I get this correctly, the reference to <anon|xxx> is not correct, since it does not allow to get re-create the original object. However, it's not clear, with an anonymous class, what could be done, short of re-creating the declaration of the class or throwing.

@masak
Copy link

masak commented Dec 29, 2020

I guess it comes down to invoking some principle of what .perl should output, and where its obligations and capabilities end. I agree that doing something sensible when the class is anonymous is difficult; but according to what specification is it better to emit something that can't be "read back in" rather than fail with an error? In my understanding, the original purpose of .perl is to produce code that can be read back in.

@lizmat
Copy link
Contributor

lizmat commented Dec 29, 2020

@masak s/.perl/.raku/ :-)

Personally, I'd rather have .raku would generate something that produces an error telling that there is no code representation possible for the source of the string given to EVAL, than having something that just silently does the wrong thing.

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

4 participants