Is this definition about Elixir ranges incorrect?

A book says a range in Elixir can be any type but this does not work,

:atom1…atom2
“a”…“b”

Anybody knows?

Then that book is plain wrong. The Range documentation clearly states:

A range represents a sequence of one or many, ascending or descending, consecutive integers.

1 Like

It’s dave thomas book,

“Ranges are represented as start…end, where start and end can be values of any type. However, if you want to
iterate over the values in a range, the two extremes must be integers.”

Yeah I agree it’s wrong.

Well ranges technically ‘can’ be any type, elixir is not a strongly typed language after all:

iex(3)> %Range{first: :a, last: "blah"}
:a.."blah"

Just that it doesn’t make much sense to do so and like a lot of other things in Elixir it doesn’t spit out an inspectable string that is reversible to the original (it might have at one point).