Spelling of ordinal numbers: Difference between revisions
→{{header|Perl 6}}: Update for Unicode 12.1, added introspection, some other tweaks and verbiage
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Update for module change) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Update for Unicode 12.1, added introspection, some other tweaks and verbiage) |
||
Line 532:
=={{header|Perl 6}}==
{{works with|Rakudo|
Rakudo version 2019.07.1 is updated to Unicode version 12.1. Unicode version 12.0 introduced some new numeric digits, which changed the output here a bit. This will ''work'' with earlier versions of Rakudo, but will yield slightly different results.
This would be pretty simple to implement from scratch; it would be straightforward to do a minor modification of the [[Number_names#Perl_6| Number names]] task code. Much simpler to just use the Lingua::EN::Numbers module from the Perl 6 ecosystem though. It will easily handles ordinal number conversions.
We need to be slightly careful of terminology. In Perl 6, 123, 00123.0, & 1.23e2 are not all integers. They are respectively an Int (integer), a Rat (rational number) and a Num (floating point number). (The fourth numeric is a Complex) For this task it doesn't much matter as the ordinal routine coerces its argument to an Int, but to Perl 6 they are different things. We can further abuse allomorphic and String types and role mixins for some somewhat non-intuitive results as well.
Note that the different allomorphic integer forms of 123 are evaluated on ''use'', not on ''assignment''. They can be passed around in parameters, but until they are used numerically, they retain their stringy characteristics and are distinctive, determinable through introspection. The numerics are evaluated on assignment, hence the stringified output not exactly matching the input format. The mixin role returns different things depending on what context you evaluate it under. When evaluated as a string it is 17, numerically, it is 123.
Perl 6 uses Unicode natively. If
It is not really clear what is meant by "Write a driver and a function...". Well, the function part is clear enough; driver not so much. Perhaps this will suffice.
<lang perl6>use Lingua::EN::Numbers;
# The task
+$_ ?? printf( "Type: \%-14s %16s : %s\n", $_.^name, $_, ordinal($_) ) !! say "\n$_:" for
# Testing
123, 00123.0, 1.23e2, 123+0i,
▲# Numerics
|
'Numeric Strings',
▲# Allomorphs
|
'Unicode Numeric Strings',
#
# digits from any block could be combined with digits from any other block.)
|
'Role Mixin',
'17' but 123;</lang>
{{out}}
<pre>Required tests:
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int
Type: Int 23456 : twenty-three thousand, four hundred fifty-sixth
Type: Int 8007006005004003 : eight quadrillion, seven trillion, six billion, five million, four thousand third
123 : one hundred twenty-third▼
123 : one hundred twenty-third▼
Optional tests - different forms of 123:
123 : one hundred twenty-third▼
123 : one hundred twenty-third▼
Numerics:
123+0i : one hundred twenty-third▼
Type: Int
Type: Rat
Type: Num
Type: Complex 123+0i : one hundred twenty-third
0b1111011 : one hundred twenty-third▼
Allomorphs:
0o173 : one hundred twenty-third▼
Type: IntStr
Type: IntStr
Type: RatStr
Type: NumStr
Type: ComplexStr
Type: IntStr
Type: IntStr
Type: IntStr
Type: RatStr
૧૨૩ : one hundred twenty-third▼
Numeric Strings:
୧୨୩ : one hundred twenty-third▼
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
၁၂၃ : one hundred twenty-third▼
Unicode Numeric Strings:
႑႒႓ : one hundred twenty-third▼
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str
Type: Str 𖩡𖩢𖩣 : one hundred twenty-third
Type: Str 𖭑𖭒𖭓 : one hundred twenty-third
Type: Str 𝟏𝟐𝟑 : one hundred twenty-third
Type: Str 𝟙𝟚𝟛 : one hundred twenty-third
Type: Str 𝟣𝟤𝟥 : one hundred twenty-third
Type: Str 𝟭𝟮𝟯 : one hundred twenty-third
Type: Str 𝟷𝟸𝟹 : one hundred twenty-third
Type: Str 𞥑𞥒𞥓 : one hundred twenty-third
Role Mixin:
=={{header|Phix}}==
|