Search code examples
booleanrangeraku

Can a Range evaluate to False in Bool context in Raku?


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

Solution

  • 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