Hi all

assuming I have a composite type

type MyType
    fielda::Int
    fieldb::Float64
    something::UTF8String
end

x=MyType(2,22.9,"foo")


#I can do this
   x.fielda=-23

function changefield!(x::MyType,fieldname::String,value)

    x.fieldname=value #this will not work.....

    return nothing
end




How can I make this function work? It should access the field "fieldname" 
and set it to the provided value.
I am aware of names(x) . I can also map these symbols to strings. 
Can eval help me here? I am never quite sure when using eval, as I am 
afraid there could be scope issues.

Thank you
Bernhard

Reply via email to