Iterate out of range

Are these results expected?

julia> iterate(3:7, 9)
(10, 10)

julia> iterate(3:7, 9)
(10, 10)

julia> iterate(3:1:7, 9)
(10, 10)

julia> iterate('c':'l','n')
('o', 'o')

julia> iterate('c':'l',15)
('\x10', '\x10')

why would they ever be called like this?

Garbage in, garbage out. It’s not defined what iterate will do if you give it an invalid iteration state as input.

3 Likes

In other cases, the implementation of iterate checks the possible input of rubbish

julia> string(iterate("cdefghi",8))
"nothing"

julia> string(iterate([1,2,3],4))
"nothing"

I/you wondered if this permissiveness was not a harbinger of possible unwanted side effects