In Glossary§
See primary documentation in context for Allomorph
A type that has two related values which may be used depending on the context. For example IntStr
allomorph is
both an Int
and a Str
, so it will be accepted by anything that expects an Int
, a Str
, or an IntStr
. Keep in mind that certain constructs, such as sets, bags, and mixes care about object identity, and so will not accept an allomorph as equivalent of its components alone.
The allomorph types IntStr
, NumStr
, RatStr
and ComplexStr
may be created as a result of parsing a string quoted with angle brackets:
say <42>.^name; # OUTPUT: «IntStrâ€Â»say <42.1e0>.^name; # OUTPUT: «NumStrâ€Â»say <42.1>.^name; # OUTPUT: «RatStrâ€Â»
Note: angle brackets can also be used to create literals for which you'd normally need to use some operator (e.g. /
for Rat
or +
for Complex
). This allows you to use such literals in places where expressions are not allowed, for example, as literals in signatures:
# Wrong, can't use an operator there:multi foo (1/3)
# Right, a Rat literal:multi foo (<1/3>)
If you do want an allomorph and not a literal Numeric
, then include whitespace around angle brackets:
say <42/1>.^name; # OUTPUT: «Ratâ€Â»say <42+0i>.^name; # OUTPUT: «Complexâ€Â»say < 42+0i >.^name; # OUTPUT: «ComplexStrâ€Â»say < 42/1 >.^name; # OUTPUT: «RatStrâ€Â»
Please see the Numerics page for a more complete description on how to work with these allomorphs.