On Tue, Apr 26, 2016 at 1:56 PM, David P. Sanders <dpsand...@gmail.com> wrote:
>
>
> El martes, 26 de abril de 2016, 12:13:22 (UTC-4), Steven G. Johnson
> escribió:
>>
>>
>>
>> On Tuesday, April 26, 2016 at 11:07:45 AM UTC-4, Pieterjan Robbe wrote:
>>>
>>> Is it possible to export all values of an an enum defined inside a
>>> module?
>>> That is, without rewriting all values after 'export'.
>>
>>
>> for s in instances(WindDirection)
>>
>>     @eval export $(symbol(s))
>>
>> end
>
>
>
> The instances function (that I didn't know about) doesn't seem to be shown
> by `methodswith` of the enumeration.
> How could we improve this?

You need to pass in the type of the argument, not the argument itself,
to methodswith

julia> @enum FRUIT apple=1 pear=2

julia> methodswith(Type{FRUIT})
5-element Array{TypeMapEntry,1}:
 convert(::Type{FRUIT}, x::Integer) at Enums.jl:79
 instances(::Type{FRUIT}) at Enums.jl:86
 typemax(x::Type{FRUIT}) at Enums.jl:83
 typemin(x::Type{FRUIT}) at Enums.jl:82
 writemime(io::IO, ::MIME{symbol("text/plain")}, ::Type{FRUIT}) at Enums.jl:103


>
> julia> @enum FRUIT apple=1 pear=2
>
> julia> methodswith(FRUIT)
> 3-element Array{Method,1}:
>  isless(::FRUIT, ::FRUIT) at Enums.jl:84
>  print(::IO, ::FRUIT) at Enums.jl:89
>  show(::IO, ::FRUIT) at Enums.jl:95
>
> julia> methodswith(FRUIT, true)
> 5-element Array{Method,1}:
>  convert{T<:Integer}(::Type{T<:Integer}, x::Enum) at Enums.jl:9
>  isless(::FRUIT, ::FRUIT) at Enums.jl:84
>  print(::IO, ::FRUIT) at Enums.jl:89
>  show(::IO, ::FRUIT) at Enums.jl:95
>  write(io::IO, x::Enum) at Enums.jl:11
>
> julia> instances(FRUIT)
> (apple::FRUIT,pear::FRUIT)

Reply via email to