ERROR: MethodError: no method matching iterate(::Symbol)

Hi,
if you try to iterate over ::Symbol you get an error:
MWE:

for i in :c @show i end
ERROR: MethodError: no method matching iterate(::Symbol)

however it works fine with Int:

for i in 5 @show i end
i = 5

note also that it works for:

for i in [:c] @show i end

Is there a solution for this?

1 Like

This is the solution, isn’t it?
Integers are iterable (I think for convenience, but have to search for the why), but not everything is iterable.

Another solution would be to implement iterate for Symbol.

Iterable Number has been usefull before broadcasting was introduced in Julia 0.5. See discussions below.

Here is listed what is iterable:

Some discussion is found here:

Linked from here:

1 Like

Is there a rationale behind for not having Iterate for Symbol?

Yes, there is no point to it.

1 Like

As in the discussions above stated: there is not much rationale behind making Number iterable.

1 Like