Skip to content

Commit 6fe30d6

Browse files
committed
'42' ~~ 1..100 coerces string to Real, etc.
1 parent 08b8886 commit 6fe30d6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

S03-operators.pod

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Synopsis 3: Perl 6 Operators
1515

1616
Created: 8 Mar 2004
1717

18-
Last Modified: 6 Jun 2011
19-
Version: 225
18+
Last Modified: 11 Jul 2011
19+
Version: 226
2020

2121
=head1 Overview
2222

@@ -3463,9 +3463,22 @@ is hereby deprecated.)
34633463
A C<Range> may be iterated only if the type in question supports the C<.succ> method.
34643464
If it does not, any attempt to iterate returns failure.
34653465

3466-
Smart matching against a C<Range> object smartmatches the
3467-
endpoints in the domain of the object being matched, so fractional
3468-
numbers are I<not> truncated before comparison to integer ranges:
3466+
Smart matching against a C<Range> object does comparisons
3467+
(by coercion, if necessary) in the C<Real> domain
3468+
if either endpoint does C<Real>. Otherwise comparison is in
3469+
the C<Stringy> domain if either argument does C<Stringy>.
3470+
Otherwise the min's type is used if it defines ordering, or if not,
3471+
the max's type. If neither min nor max have an ordering,
3472+
dispatch to .ACCEPTS fails. It may also fail if the ordering
3473+
in question does not have any way to coerce the object
3474+
being smartmatched into an appropropriate type implied by the
3475+
chosen domain of ordering.
3476+
3477+
In general, the domain of comparison should be a type that can
3478+
represent all the values in question, if possible. Hence, since Int
3479+
is not such a type, it is promoted to a Real, so fractional numbers
3480+
are I<not> truncated before comparison to integer ranges. Instead the
3481+
integers are assumed to represent points on the real number line:
34693482

34703483
1.5 ~~ 1^..^2 # true, equivalent to 1 < 1.5 < 2
34713484
2.1 ~~ 1..2 # false, equivalent to 1 <= 2.1 <= 2
@@ -3481,8 +3494,8 @@ inferred from the right operand. (A star on both sides is not allowed.)
34813494
'a'..* # 'a' le $_
34823495
*..0 # -Inf .. 0
34833496
*..* # Illegal
3484-
1.2.3..* # Any version higher than 1.2.3.
3485-
May..* # May through December
3497+
v1.2.3 .. * # Any version higher than 1.2.3.
3498+
May .. * # May through December
34863499

34873500
An empty range cannot be iterated; it returns a C<Nil> instead. An empty
34883501
range still has a defined C<.min> and C<.max>, but one of the following is

0 commit comments

Comments
 (0)