Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can native attributes be used as bind target in parameters?

Tags:

syntax

raku

According to the 6.d (current version) check list, they can.

However,

class Foo { 
    has num $.numillo;
    submethod BUILD( :$numillo = 3.5 ) {}
};
my $foo = Foo.new;
say $foo.raku; # OUTPUT:  «Foo.new(numillo => 0e0)␤»  

The atttribute does not seem to be bindable, or at least does not get a value assigned. Am I missing something here?

like image 214
jjmerelo Avatar asked Dec 17 '19 07:12

jjmerelo


1 Answers

You are just assigning a value to a named parameter in BUILD, not to the attribute!

submethod BUILD( :$!numillo = 3.5e0 ) {}

should fix that (note the ! in the signature). Please also note that 3.5 is not a num, you would have to make it one by adding e0.

like image 139
Elizabeth Mattijsen Avatar answered Oct 21 '22 16:10

Elizabeth Mattijsen