Cool. I find the companion macro @unpack super handy too for functions which take as arguments types with many fields. Instead of:
show = ec.title.show zlevel = ec.title.zlevel z = ec.title.z do @unpack ec.title: show, zlevel, z Mauro On Tue, 2015-12-29 at 21:16, Randy Zwitch <randy.zwi...@fuqua.duke.edu> wrote: > Thanks Mauro, the @pack macro solution looks interesting, I'll try that out > > On Tuesday, December 29, 2015 at 3:00:12 PM UTC-5, Mauro wrote: >> >> You could use the @pack macro from Parameters.jl: >> >> @pack ec.title: show, zlevel, z >> >> which is equivalent to your >> >> ec.title.show = show >> ec.title.zlevel = zlevel >> ec.title.z = z >> >> Otherwise use `setfield!`: >> >> function f(t;kws...) >> for (s,v) in kws >> setfield!(t, s, v) >> end >> end >> >> On Tue, 2015-12-29 at 20:34, Randy Zwitch <randy....@fuqua.duke.edu >> <javascript:>> wrote: >> > I feel like I should be so much better at this than I am... >> > >> > How can I take code like: >> > >> > ec.title.show = show >> > ec.title.zlevel = zlevel >> > ec.title.z = z >> > >> > And change it to something like >> > >> > for val in [:show, :zlevel, :z] >> > :(ec.title.$val) = :($val) >> > end >> > >> > I'm just trying to dynamically reference and set the value of the >> composite >> > type field equal to the values passed to a function's keyword arguments. >>