Allomorph Reference
Dual value number and string
What it is #
Position in the hierarchy #
| Inherits from | — |
| Does | — |
| Inherited by | IntStr, NumStr, RatStr, ComplexStr |
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 ACCEPTS #
multi method ACCEPTS(Allomorph:D: Any:D \a)
If the a parameter is Numeric (including another allomorph), checks if invocant's Numeric value ACCEPTS a. If the a parameter is Str, checks if invocant's Str value ACCEPTS a. If the a parameter is anything else, checks if both
method Bool #
multi method Bool(::?CLASS:D:)
Returns False if the invocant is numerically 0, otherwise returns True. The Str value of the invocant is not considered. Note: For the Allomorph subclass RatStr also see Rational.Bool.
method chomp #
method chomp(Allomorph:D:)
Calls Str.chomp on the invocant's Str value.
method chop #
method chop(Allomorph:D: |c)
Calls Str.chop on the invocant's Str value.
method comb #
method comb(Allomorph:D: |c)
Calls Str.comb on the invocant's Str value.
method fc #
method fc(Allomorph:D:)
Calls Str.fc on the invocant's Str value.
method flip #
method flip(Allomorph:D:)
Calls Str.flip on the invocant's Str value.
method lc #
method lc(Allomorph:D:)
Calls Str.lc on the invocant's Str value.
method pred #
method pred(Allomorph:D:)
Calls Numeric.pred on the invocant's numeric value.
method raku #
multi method raku(Allomorph:D:)
Return a representation of the object that can be used via EVAL to reconstruct the value of the object.
method samecase #
method samecase(Allomorph:D: |c)
Calls Str.samecase on the invocant's Str value.
method samemark #
method samemark(Allomorph:D: |c)
Calls Str.samemark on the invocant's Str value.
method samespace #
method samespace(Allomorph:D: |c)
See Is Str.samespace an implementation detail or not? · Issue #4318 · rakudo/rakudo · GitHub
method split #
method split(Allomorph:D: |c)
Calls Str.split on the invocant's Str value.
method Str #
method Str(Allomorph:D:)
Returns the Str value of the invocant.
method subst #
method subst(Allomorph:D: |c)
Calls Str.subst on the invocant's Str value.
method subst-mutate #
method subst-mutate(Allomorph:D \SELF: |c)
Calls Str.subst-mutate on the invocant's Str value.
method substr #
method substr(Allomorph:D: |c)
Calls Str.substr on the invocant's Str value.
method substr-rw #
method substr-rw(Allomorph:D \SELF: $start = 0, $want = Whatever)
Calls Str.substr-rw on the invocant's Str value.
method succ #
method succ(Allomorph:D:)
Calls Numeric.succ on the invocant's numeric value.
method tc #
method tc(Allomorph:D:)
Calls Str.tc on the invocant's Str value.
method tclc #
method tclc(Allomorph:D:)
Calls Str.tclc on the invocant's Str value.
method trim #
method trim(Allomorph:D:)
Calls Str.trim on the invocant's Str value.
method trim-leading #
method trim-leading(Allomorph:D:)
Calls Str.trim-leading on the invocant's Str value.
method trim-trailing #
method trim-trailing(Allomorph:D:)
Calls Str.trim-trailing on the invocant's Str value.
method uc #
method uc(Allomorph:D:)
Calls Str.uc on the invocant's Str value.
method WHICH #
multi method WHICH(Allomorph:D:)
Returns an object of type ValueObjAt which uniquely identifies the object.
infix cmp #
multi infix:<cmp>(Allomorph:D $a, Allomorph:D $b)
Compare two Allomorph objects. The comparison is done on the Numeric value first and then on the Str value. If you want to compare in a different order then you would coerce to a Numeric or Str value first:
infix eqv #
multi infix:<eqv>(Allomorph:D $a, Allomorph:D $b --> Bool:D)
Returns Bool:D.
Returns True if the two Allomorph $a and $b are of the same type, their Numeric values are equivalent and their Str values are also equivalent. 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 · 3 ok · 1 rakupp-differs
class Allomorph is Str { }Not executed: the documentation states no expected output for this example.
my $c = <42+0i>; say $c.^name; # OUTPUT: «ComplexStr» my $i = <42>; say $i.^name; # OUTPUT: «IntStr» my $n = <42.1e0>; say $n.^name; # OUTPUT: «NumStr» my $r = <42.1>; say $r.^name; # OUTPUT: «RatStr»
ComplexStr
IntStr
NumStr
RatStr
Complex
IntStr
NumStr
RatStr
Complex
IntStr
NumStr
RatStr
Both engines agree; the documentation states something else. Trust the engines.
my ($complex-str, $int-str, $num-str, $rat-str)
= < 42+0i 42 42e10 42.1 >;
my (Complex $complex, Int $int, Num $num, Rat $rat)
= $complex-str, $int-str, $num-str, $rat-str; # OK!
my Str @strings
= $complex-str, $int-str, $num-str, $rat-str; # OK!
# ∈ operator cares about object identity
say 42+0i ∈ < 42+0i 42 42e10 42.1 >; # OUTPUT: «False»
say 42 ∈ < 42+0i 42 42e10 42.1 >; # OUTPUT: «False»
say 42e10 ∈ < 42+0i 42 42e10 42.1 >; # OUTPUT: «False»
say 42.1 ∈ < 42+0i 42 42e10 42.1 >; # OUTPUT: «False»False
False
False
False
False
False
False
False
True
False
False
False
Raku++ disagrees with both the documentation and Rakudo — a defect.
say "5.0" ~~ <5>; # OUTPUT: «False» say 5.0 ~~ <5>; # OUTPUT: «True» say <5.0> ~~ <5>; # OUTPUT: «True»
False
True
True
Documentation, Rakudo and Raku++ all agree.
my $f = <42.1e0>; say $f.WHICH; # OUTPUT: «NumStr|Num|42.1|Str|42.1e0»
NumStr|Num|42.1|Str|42.1e0
Documentation, Rakudo and Raku++ all agree.
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»
Less
More
Documentation, Rakudo and Raku++ all agree.