Skip to content

Iteration over a symbol does not work #18509

Closed
@dpsanders

Description

@dpsanders
julia> setdiff([1,2], 1)
1-element Array{Int64,1}:
 2

but with symbols it doesn't work:

julia> setdiff([:a, :b], :a)
--------------------------------------------------------------------------------
MethodError                                   Stacktrace (most recent call last)
[#2] — setdiff(::Array{Symbol,1}, ::Symbol)
       ⌙ at array.jl:1466

[#1] — union!(::Set{Any}, ::Symbol)
       ⌙ at set.jl:63

MethodError: no method matching start(::Symbol)
Closest candidates are:
  start(::SimpleVector) at essentials.jl:170
  start(::Base.MethodList) at reflection.jl:258
  start(::IntSet) at intset.jl:184

As per the error message, this is apparently because

julia> start(1)
false

julia> start(:a)
MethodError: no method matching start(::Symbol)
Closest candidates are:
  start(::SimpleVector) at essentials.jl:170
  start(::Base.MethodList) at reflection.jl:258
  start(::IntSet) at intset.jl:184

Is there a rationale for this? Or can we add iteration to symbols?

Alternatively, is there a way to ensure something is an array for setdiff to work?
I guess using [v;], but this feels hacky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    won't changeIndicates that work won't continue on an issue or pull request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions