this new question is a follow up to my previous that has emerged as I flesh things out. Please note that I have also done some research and I am consciously skirting the Scalar Mixins bug mentioned here. So I am mixing the role in to the Object and not to the Scalar container.
Big picture is to do math operations that also perform simple error calculations.
Here is a concise version of my failing code:
1 role Error {
2 has $.abs-error
3 }
4
5 multi prefix:<-> ( Error:D $x ) is default {
6 # - $x; # fails - enters an infinite loop
7 # - $x.Real; # fails - does not drop the Error mixin
8 ( 0 - $x ) does Error($x.abs-error) # works - but relies on the infix:<-> form
9 }
10
11 my $dog = 12.5 does Error(0.5);
12
13 #what i have...
14 say $dog; #12.5
15 say $dog.WHAT; #(Rat+{Error})
16 say $dog.abs-error; #0.5
17
18 #what i want...
19 say (-$dog); #-12.5
20 say (-$dog).WHAT; #(Rat+{Error})
21 say (-$dog).abs-error; #0.5
The heart of my question is:
- as a user of $dog I can get at the value of the variable (12.5) on line 14
- sooo how can I get the unadorned value somewhere around line 7?
I have tried (desperately?) a few things:
- coercion to Real (still get the mixed in object)
- assignment to Real container (that permits Rat+{Error} ~~ Real)
- $dog.default => No such method 'default' for invocant of type 'Rat+{Error}'
Thanks for all advice!!