diff --git a/doc/Type/ComplexStr.pod6 b/doc/Type/ComplexStr.pod6 index a2c1afa91..731ca57ed 100644 --- a/doc/Type/ComplexStr.pod6 +++ b/doc/Type/ComplexStr.pod6 @@ -4,24 +4,24 @@ =SUBTITLE Dual value complex number and string - class ComplexStr is Complex is Str {} + class ComplexStr is Allomorph is Complex {} -The dual value types (often referred to as L) -allow for the representation of a value as both a string and a numeric type. Typically -they will be created for you when the context is "stringy" but they can be determined -to be numbers, such as in some L: +C is a dual value type, a subclass of both +L«C|/type/Allomorph», hence L«C|/type/Str», and +L«C|/type/Complex». - my $f = <42+0i>; say $f.^name; # OUTPUT: «ComplexStr␤» +See L«C|/type/Allomorph» for further details. -As a subclass of both L«C|/type/Complex» and L«C|/type/Str», -a C will be accepted where either is expected. However, -C does not share object identity with C- or C-only -variants: +=begin code +my $complex-str = <42+0i>; +say $complex-str.^name; # OUTPUT: «ComplexStr␤» - my $complex-str = < 42+0i >; - my Complex $complex = $complex-str; # OK! - my Str $str = $complex-str; # OK! - say 42+0i ∈ <42+0i 55 1>; # False; ∈ operator cares about object identity +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␤» +=end code =head1 Methods @@ -36,17 +36,6 @@ directly the values can be whatever is required: say +$f; # OUTPUT: «42+0i␤» say ~$f; # OUTPUT: «"forty two (but complicated)"␤» -=head2 method Bool - -Defined as: - - multi method Bool(ComplexStr:D: --> Bool:D) - -I. - -Returns C if the invocant is numerically C<±0±0i>, otherwise returns C. String portion -is not considered. - =head2 method Capture Defined as: @@ -85,41 +74,15 @@ coercion L with C. The C<:D> variant returns the result of that coercion. The C<:U> variant issues a warning about using an uninitialized value in numeric context and then returns value C<0e0>. -=head2 method Str - -Returns the string value of the C. - -=head2 method ACCEPTS - -Defined as: - - multi method ACCEPTS(ComplexStr:D: Any:D $value) - -If C<$value> is L (including another -L), checks if invocant's -L part L the C<$value>. -If C<$value> is L, checks if invocant's L part -L the C<$value>. If value is anything else, -checks if both L and L parts C the C<$value>. - - say < 5+0i> ~~ "5.0"; # OUTPUT: «False␤» - say < 5+0i> ~~ 5.0 ; # OUTPUT: «True␤» - say < 5+0i> ~~ <5.0>; # OUTPUT: «True␤» - =head1 Operators -=head2 infix cmp - - multi sub infix:(ComplexStr:D $a, ComplexStr:D $b) +=head2 infix C«===» -Compare two C objects. The comparison is done on the C value first and -then on the C value. If you want to compare in a different order then you would -coerce to the C or C values first: + multi sub infix:<===>(ComplexStr:D $a, ComplexStr:D $b) - my $f = ComplexStr.new(42+0i, "smaller"); - my $g = ComplexStr.new(43+0i, "larger"); - say $f cmp $g; # OUTPUT: «Less␤» - say $f.Str cmp $g.Str; # OUTPUT: «More␤» +C Value identity operator. Returns C if the C +values of C<$a> and C<$b> are L and their C +values are also L. Returns C otherwise. =end pod diff --git a/doc/Type/IntStr.pod6 b/doc/Type/IntStr.pod6 index 09dfb2880..b3e8060bc 100644 --- a/doc/Type/IntStr.pod6 +++ b/doc/Type/IntStr.pod6 @@ -4,23 +4,24 @@ =SUBTITLE Dual value integer and string - class IntStr is Int is Str { } + class IntStr is Allomorph is Int { } -The dual value types (often referred to as L) -allow for the representation of a value as both a string and a numeric type. Typically -they will be created for you when the context is "stringy" but they can be determined -to be numbers, such as in some L: +C is a dual value type, a subclass of both +L«C|/type/Allomorph», hence L«C|/type/Str», and +L«C|/type/Int». - my $f = <42>; say $f.^name; # OUTPUT: «IntStr␤» +See L«C|/type/Allomorph» for further details. -As a subclass of both L«C|/type/Int» and L«C|/type/Str», an C -will be accepted where either is expected. However, C does not share -object identity with C- or C-only variants: +=begin code +my $int-str = <42>; +say $int-str.^name; # OUTPUT: «IntStr␤» - my $int-str = <42>; - my Int $int = $int-str; # OK! - my Str $str = $int-str; # OK! - say 42 ∈ <42 55 1>; # False; ∈ operator cares about object identity +my Int $int = $int-str; # OK! +my Str $str = $int-str; # OK! + +# ∈ operator cares about object identity +say 42 ∈ <42 55 1>; # OUTPUT: «False␤» +=end code =head1 Methods @@ -35,17 +36,6 @@ directly the values can be whatever is required: say +$f; # OUTPUT: «42␤» say ~$f; # OUTPUT: «"forty two"␤» -=head2 method Bool - -Defined as: - - multi method Bool(IntStr:D: --> Bool:D) - -I. - -Returns C if the invocant is numerically C<0>, otherwise returns C. String portion -is not considered. - =head2 method Int method Int @@ -72,41 +62,15 @@ Defined as: The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues a warning about using an uninitialized value in numeric context and then returns value C<0>. -=head2 method Str - -Returns the string value of the C. - -=head2 method ACCEPTS - -Defined as: - - multi method ACCEPTS(IntStr:D: Any:D $value) - -If C<$value> is L (including another -L), checks if invocant's -L part L the C<$value>. If -C<$value> is L, checks if invocant's L part -L the C<$value>. If value is anything else, -checks if both L and L parts C the C<$value>. - - say <5> ~~ "5.0"; # OUTPUT: «False␤» - say <5> ~~ 5.0 ; # OUTPUT: «True␤» - say <5> ~~ <5.0>; # OUTPUT: «True␤» - =head1 Operators -=head2 infix cmp - - multi sub infix:(IntStr:D $a, IntStr:D $b) +=head2 infix C«===» -Compare two C objects. The comparison is done on the C value first and -then on the C value. If you want to compare in a different order then you would -coerce to an C or C value first: + multi sub infix:<===>(IntStr:D $a, IntStr:D $b) - my $f = IntStr.new(42, "smaller"); - my $g = IntStr.new(43, "larger"); - say $f cmp $g; # OUTPUT: «Less␤» - say $f.Str cmp $g.Str; # OUTPUT: «More␤» +C Value identity operator. Returns C if the C +values of C<$a> and C<$b> are L and their C +values are also L. Returns C otherwise. =end pod diff --git a/doc/Type/NumStr.pod6 b/doc/Type/NumStr.pod6 index 2342df92f..a3f680137 100644 --- a/doc/Type/NumStr.pod6 +++ b/doc/Type/NumStr.pod6 @@ -4,23 +4,24 @@ =SUBTITLE Dual value floating-point number and string - class NumStr is Num is Str { } + class NumStr is Allomorph is Num { } -The dual value types (often referred to as L) -allow for the representation of a value as both a string and a numeric type. Typically -they will be created for you when the context is "stringy" but they can be determined -to be numbers, such as in some L: +C is a dual value type, a subclass of both +L«C|/type/Allomorph», hence L«C|/type/Str», and +L«C|/type/Num». - my $f = <42.1e0>; say $f.^name; # OUTPUT: «NumStr␤» +See L«C|/type/Allomorph» for further details. -As a subclass of both L«C|/type/Num» and L«C|/type/Str», a C -will be accepted where either is expected. However, C does not share -object identity with C- or C-only variants: +=begin code +my $num-str = <42.1e0>; +say $num-str.^name; # OUTPUT: «NumStr␤» - my $num-str = <42e10>; - my Num $num = $num-str; # OK! - my Str $str = $num-str; # OK! - say 42e10 ∈ <42e10 55 1>; # False; ∈ operator cares about object identity +my Num $num = $num-str; # OK! +my Str $str = $num-str; # OK! + +# ∈ operator cares about object identity +say 42e10 ∈ <42e10 55 1>; # OUTPUT: «False␤» +=end code =head1 Methods @@ -35,17 +36,6 @@ directly the values can be whatever is required: say +$f; # OUTPUT: «42.1␤» say ~$f; # OUTPUT: «"forty two and a bit"␤» -=head2 method Bool - -Defined as: - - multi method Bool(NumStr:D: --> Bool:D) - -I. - -Returns C if the invocant is numerically C<±0e0>, otherwise returns C. String portion -is not considered. - =head2 method Num method Num @@ -72,41 +62,15 @@ Defined as: The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues a warning about using an uninitialized value in numeric context and then returns value C<0e0>. -=head2 method Str - -Returns the string value of the C. - -=head2 method ACCEPTS - -Defined as: - - multi method ACCEPTS(NumStr:D: Any:D $value) - -If C<$value> is L (including another -L), checks if invocant's -L part L the C<$value>. If -C<$value> is L, checks if invocant's L part -L the C<$value>. If value is anything else, -checks if both L and L parts C the C<$value>. - - say <5e0> ~~ "5.0"; # OUTPUT: «False␤» - say <5e0> ~~ 5.0 ; # OUTPUT: «True␤» - say <5e0> ~~ <5.0>; # OUTPUT: «True␤» - =head1 Operators -=head2 infix cmp - - multi sub infix:(NumStr:D $a, NumStr:D $b) +=head2 infix C«===» -Compare two C objects. The comparison is done on the C value first and -then on the C value. If you want to compare in a different order then you would -coerce to a C or C value first: + multi sub infix:<===>(NumStr:D $a, NumStr:D $b) - my $f = NumStr.new(42.1e0, "smaller"); - my $g = NumStr.new(43.1e0, "larger"); - say $f cmp $g; # OUTPUT: «Less␤» - say $f.Str cmp $g.Str; # OUTPUT: «More␤» +C Value identity operator. Returns C if the C +values of C<$a> and C<$b> are L and their C +values are also L. Returns C otherwise. =end pod diff --git a/doc/Type/RatStr.pod6 b/doc/Type/RatStr.pod6 index 86ce69d6c..04c9a5a94 100644 --- a/doc/Type/RatStr.pod6 +++ b/doc/Type/RatStr.pod6 @@ -4,23 +4,24 @@ =SUBTITLE Dual value rational number and string - class RatStr is Rat is Str {} + class RatStr is Allomorph is Rat {} -The dual value types (often referred to as L) -allow for the representation of a value as both a string and a numeric type. Typically -they will be created for you when the context is "stringy" but they can be determined -to be numbers, such as in some L: +C is a dual value type, a subclass of both +L«C|/type/Allomorph», hence L«C|/type/Str», and +L«C|/type/Rat». - my $f = <42.1>; say $f.^name; # OUTPUT: «RatStr␤» +See L«C|/type/Allomorph» for further details. -As a subclass of both L«C|/type/Rat» and L«C|/type/Str», a C -will be accepted where either is expected. However, C does not share -object identity with C- or C-only variants: +=begin code +my $rat-str = <42.1>; +say $rat-str.^name; # OUTPUT: «RatStr␤» - my $rat-str = <42.1>; - my Rat $rat = $rat-str; # OK! - my Str $str = $rat-str; # OK! - say 42.1 ∈ <42.1 55 1>; # False; ∈ operator cares about object identity +my Rat $rat = $rat-str; # OK! +my Str $str = $rat-str; # OK! + +# ∈ operator cares about object identity +say 42.1 ∈ <42.1 55 1>; # OUTPUT: «False␤» +=end code =head1 Methods @@ -35,18 +36,6 @@ directly the values can be whatever is required: say +$f; # OUTPUT: «42.1␤» say ~$f; # OUTPUT: «"forty two and a bit"␤» -=head2 method Bool - -Defined as: - - multi method Bool(RatStr:D: --> Bool:D) - -I. - -Returns C if the L of the numeric portion is C<0>, otherwise returns C. -This applies for C«< 0/0 >» zero-denominator L as well, despite C«?< 0/0 >.Num» being -C. String portion is not considered. - =head2 method Capture Defined as: @@ -81,41 +70,15 @@ Defined as: The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues a warning about using an uninitialized value in numeric context and then returns value C<0.0>. -=head2 method Str - -Returns the string value of the C. - -=head2 method ACCEPTS - -Defined as: - - multi method ACCEPTS(RatStr:D: Any:D $value) - -If C<$value> is L (including another -L), checks if invocant's -L part L the C<$value>. If -C<$value> is L, checks if invocant's L part -L the C<$value>. If value is anything else, -checks if both L and L parts C the C<$value>. - - say <5.0> ~~ "5"; # OUTPUT: «False␤» - say <5.0> ~~ 5 ; # OUTPUT: «True␤» - say <5.0> ~~ <5>; # OUTPUT: «True␤» - =head1 Operators -=head2 infix cmp - - multi sub infix:(RatStr:D $a, RatStr:D $b) +=head2 infix C«===» -Compare two C objects. The comparison is done on the C value first and -then on the C value. If you want to compare in a different order then you would -coerce to the C or C values first: + multi sub infix:<===>(RatStr:D $a, RatStr:D $b) - my $f = RatStr.new(42.1, "smaller"); - my $g = RatStr.new(43.1, "larger"); - say $f cmp $g; # OUTPUT: «Less␤» - say $f.Str cmp $g.Str; # OUTPUT: «More␤» +C Value identity operator. Returns C if the C +values of C<$a> and C<$b> are L and their C +values are also L. Returns C otherwise. =end pod