Thanks too. I have to start studying the c api as well.
quinta-feira, 10 de Setembro de 2015 às 03:06:03 UTC+1, Yichao Yu escreveu: > > On Wed, Sep 9, 2015 at 9:27 PM, Luke Stagner <[email protected] > <javascript:>> wrote: > > Firstly, instead of using ```symbol("is_continuous")``` you can use the > > colon notation ```:is_continuous```. Secondly, you can do element wise > > comparison by using ```.==``` operator. This will return a BitArray. You > can > > then find where the BitArray is true by using the ```find``` function > which > > returns an array of indices. > > > > So for your case all you would need to do is > > ``` > > index = find(fn .== :is_continuous) > > ``` > > > > findfirst(fn, :is_continuous) > > There's also the c api jl_field_index that can be called with > `ccall(:jl_field_index, Cint, (Any, Any, Cint), GMT_PALETTE, > :is_continuous, 1) + 1` > > > > > On Wednesday, September 9, 2015 at 6:01:47 PM UTC-7, J Luis wrote: > >> > >> So I need to find position of a certain type member in a type. Easy, I > >> though > >> > >> julia> fn = fieldnames(GMT_PALETTE) > >> 9-element Array{Symbol,1}: > >> :n_headers > >> :n_colors > >> :alloc_level > >> :auto_scale > >> :model > >> :is_gray > >> :is_bw > >> :is_continuous > >> :z_unit_to_meter > >> > >> julia> search(fn,"is_continuous") > >> ERROR: MethodError: `search` has no method matching > >> search(::Array{Symbol,1}, ::ASCIIString) > >> Closest candidates are: > >> search(::AbstractString, ::AbstractString) > >> search(::AbstractString, ::AbstractString, ::Integer) > >> > >> Went to the docs and found the "symbol" function and though, ok now it > >> will work > >> > >> julia> search(fn,symbol("is_continuous")) > >> ERROR: MethodError: `search` has no method matching > >> search(::Array{Symbol,1}, ::Symbol) > >> > >> Ok, I can do a loop over the number of elements and ask > >> > >> fn[k] == symbol("is_continuous") > >> > >> but isn't there a more compact way of do this ? > >> > >> (I confess this parts of Julia are annoying) > >> > >> Thanks >
