dynamic names can be handy, but they are also quite slow. symbol(string(nomes[1])) === nomes[1]
On Mon, Mar 24, 2014 at 11:13 PM, J Luis <[email protected]> wrote: > Thanks > > So this means we cannot do the dynamic names as in Matlab (where the "b" is > the member name) > > BTW, I needed to extract the member name as a string to compare with another > string and the only way I got it done was with > > julia> nomes=names(MyType) > 1-element Array{Symbol,1}: > :a > > julia> @sprintf("%s", nomes[1]) > "a" > > > but don't know how to do it the other way around. Not that I need it now but > Matlab dynamic names are quite handy. > > Terça-feira, 25 de Março de 2014 3:01:13 UTC, Sam L escreveu: >> >> After some experimentation, it looks like second way takes a symbol or >> variable who's value is a symbol. >> >> julia> type MyType; a::Int; end >> >> julia> x = MyType(3) >> MyType(3) >> >> julia> x.a >> 3 >> >> julia> x.(a) >> ERROR: a not defined >> >> julia> x.(:a) >> 3 >> >> julia> b = :a >> :a >> >> julia> x.(b) >> 3 >> >> >> On Monday, March 24, 2014 7:46:38 PM UTC-7, J Luis wrote: >>> >>> The doc of getfield says >>> >>> getfield(value, name::Symbol) >>> >>> Extract a named field from a value of composite type. The syntax a.b >>> calls >>> getfield(a, :b), and the syntax a.(b) calls getfield(a, b). >>> >>> >>> but when I try the a.(b) variation, it errors (or it's me who errors?) >>> >>> julia> gmt_modules.write >>> "<?I,>?O" >>> >>> julia> gmt_modules.(write) >>> ERROR: type: getfield: expected Symbol, got Function >>> >>> >>> >>> >
