ComplexStr Reference
Dual value complex number and string
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method new #
method new(Complex $i, Str $s)
The constructor requires both the Complex and the Str value, when constructing one directly the values can be whatever is required:
method Capture #
method Capture(ComplexStr:D: --> Capture:D)
Returns Capture:D.
Equivalent to Mu.Capture.
method Complex #
method Complex
Returns the Complex value of the ComplexStr.
method Numeric #
multi method Numeric(ComplexStr:D: --> Complex:D)
multi method Numeric(ComplexStr:U: --> Complex:D)
Returns Complex:D.
The :D variant returns the numeric portion of the invocant. The :U variant issues a warning about using an uninitialized value in numeric context and then returns value <0+0i>.
method Real #
multi method Real(ComplexStr:D: --> Num:D)
multi method Real(ComplexStr:U: --> Num:D)
Returns Num:D.
Coerces the numeric portion of the invocant to Num. If the imaginary part isn't approximately zero, coercion fails with X::Numeric::Real. The :D variant returns the result of that coercion. The :U variant issues a warning about using an uninitialized value in numeric context and then returns value 0e0.
infix C«===» #
multi infix:<===>(ComplexStr:D $a, ComplexStr:D $b)
ComplexStr Value identity operator. Returns True if the Complex values of $a and $b are identical and their Str values are also identical. Returns False otherwise.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
1 doc-drift · 1 no-output · 1 not-runnable
class ComplexStr is Allomorph is Complex {}Not executed: the documentation states no expected output for this example.
my $complex-str = <42+0i>; say $complex-str.^name; # OUTPUT: «ComplexStr» my Complex $complex = $complex-str; # OK! my Str $str = $complex-str; # OK! # ∈ operator cares about object identity say 42+0i ∈ <42+0i 55 1>; # OUTPUT: «False»
Neither engine can run this in isolation — the example depends on context from the surrounding text.
my $f = ComplexStr.new(42+0i, "forty two (but complicated)"); say +$f; # OUTPUT: «42+0i» say ~$f; # OUTPUT: «"forty two (but complicated)"»
42+0i
"forty two (but complicated)"
42+0i
forty two (but complicated)
42+0i
forty two (but complicated)
Both engines agree; the documentation states something else. Trust the engines.