Can a Range evaluate to False in Bool context in Raku?
Asked Answered
C

1

6

While making use of a Range to solve a problem I noticed that a Range with 0 elems would be True as a Bool. In what scenarios could a Range be False?

[0] > (^0).so
True
[1] > (1..0).so
True
Coarse answered 13/4, 2024 at 11:46 Comment(0)
C
7

The behavior does not match the design docs up to Raku v6.d, an empty Range is expected to be False. This is being addressed with Raku v6.e.

[0] > use v6.e.PREVIEW
Nil
[1] > (^0).so
False
[2] > (1..0).so
False

https://github.com/Raku/old-design-docs/blob/a4c36c683dafdad0bb55996e78b66a1f48fc703c/S03-operators.pod#L3608

https://github.com/rakudo/rakudo/issues/5222

Coarse answered 13/4, 2024 at 11:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.