Dual value integer and string
is Allomorph is Int
IntStr
is a dual value type, a subclass of both Allomorph
, hence Str
, and Int
.
See Allomorph
for further details.
my = <42>;say .^name; # OUTPUT: «IntStr»my Int = ; # OK!my Str = ; # OK!# ∈ operator cares about object identitysay 42 ∈ <42 55 1>; # OUTPUT: «False»
method new(Int , Str )
The constructor requires both the Int
and the Str
value, when constructing one directly the values can be whatever is required:
my = IntStr.new(42, "forty two");say +; # OUTPUT: «42»say ~; # OUTPUT: «"forty two"»
method Int
Returns the integer value of the IntStr
.
multi method Numeric(IntStr: --> Int)multi method Numeric(IntStr: --> Int)
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
.
multi method Real(IntStr: --> Int)multi method Real(IntStr: --> Int)
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
.
===
multi sub infix:<===>(IntStr , IntStr )
IntStr
Value identity operator. Returns True
if the Int
values of $a
and $b
are identical and their Str
values are also identical. Returns False
otherwise.