You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rakudo-moar 6d58e0b: OUTPUT: «Cannot assign to an immutable value in block at line 1»
Expected Behavior
my$a= A.new( s => 'Hello' );
Should create a new object $a with $a.s containing the string 'Hello';
For easy golfing, the entire string used to illustrate the problem is:
m: class A is repr('CStruct') { has Str $.s is rw; }; my $a = A.new( s => 'Hello' );
Oddly enough, the solution involves using nqp;
class A is repr('CStruct') {
has Str $!s;
method s is rw {
use nqp;
Proxy.new:
FETCH => -> $ {$!s},
STORE => -> $, $new { nqp::bindattr( nqp::decont(self), A, '$!s', nqp::unbox_s(~$new) ) }
}
}
my $a = A.new; $a.s = Hello';
$a.s.say
Again, this can be replicated in IRC using:
m: class A is repr('CStruct') { has Str $!s; method s is rw { use nqp; Proxy.new: FETCH => -> $ {$!s}, STORE => -> $, $new { nqp::bindattr( nqp::decont(self), A, '$!s', nqp::unbox_s(~$new) ); }; }; }; my $a = A.new; $a.s = 'Hello'; $a.s.say
This trick was discovered by looking through old code from FROGGS in p6-XML-LibXML.
Environment
This was found on the #perl6 IRC bot camelia.
rakudo (2018.12.165.g.6.d.58.e.0.b.0.b)
The text was updated successfully, but these errors were encountered:
The Problem
This should create a CStruct backed object with a string attribute that allows changing.
But instead, this occurs:
rakudo-moar 6d58e0b: OUTPUT: «Cannot assign to an immutable value in block at line 1»
Expected Behavior
Should create a new object $a with $a.s containing the string 'Hello';
For easy golfing, the entire string used to illustrate the problem is:
m: class A is repr('CStruct') { has Str $.s is rw; }; my $a = A.new( s => 'Hello' );
Oddly enough, the solution involves using nqp;
Again, this can be replicated in IRC using:
m: class A is repr('CStruct') { has Str $!s; method s is rw { use nqp; Proxy.new: FETCH => -> $ {$!s}, STORE => -> $,$new { nqp::bindattr( nqp::decont(self), A, '$ !s', nqp::unbox_s(~$new) ); }; }; }; my $a = A.new; $a.s = 'Hello'; $a.s.say
This trick was discovered by looking through old code from FROGGS in p6-XML-LibXML.
Environment
This was found on the #perl6 IRC bot camelia.
rakudo (2018.12.165.g.6.d.58.e.0.b.0.b)
The text was updated successfully, but these errors were encountered: