[julia-users] how to check if a type has a certain field

2015-05-12 Thread K leo
type Tech cl::Array{Float64,1} function Tech() this = new() this.cl=[1:4] this end end tech = Tech() How can I check if tech.asf is not a valid field?

Re: [julia-users] how to check if a type has a certain field

2015-05-12 Thread René Donner
Hi, you could look up the name in the list of fieldnames: in(:asf, names(Tech)) will return true if Tech has a field "asf", false otherwise. I don't know what your usage scenario is, but perhaps a Dict() might be an alternative, where you can set arbitrary fields and query their existence wi

Re: [julia-users] how to check if a type has a certain field

2015-05-12 Thread Kuba Roth
It seems names() is deprecated now and fieldnames() is preferable. type myType a b c end fields = ["a","B","c","d"] #field names to test for f in fields println( in(symbol(f), fieldnames(myType))) end