That's what I was after thanks Natnaiel! So I can now at least get a macro to expand to a function which I can store per type, and call that at the start of process to fetch the class scope names to local variables :)
This is a great workaround until there is a neater way to get the names of a function arguments into the local scope. On Wednesday, June 11, 2014 8:17:48 AM UTC+8, Nathaniel Nicandro wrote: > > Also you can get around having to specify a variable to hold the names of > the type by adding an extra parameter to the macro > > > > macro fetch(name, typ) > _typ = eval(typ) > r = Expr(:block) > r.args = [:($n = $name.$n) for n in _typ.names] > return esc(r) > end > > macroexpand(:(@fetch model CircuitModel)) > > > > On Tuesday, June 10, 2014 5:08:57 AM UTC-5, Yuuki Soho wrote: >> >> This should do what you want: >> >>> >>>>> const circuitModelNames = names(CircuitModel) >>>>> >>>>> >>>>> macro fetch(ex) >>>>> >>>>> Expr(:block, [ :($(circuitModelNames[i]) = $ex.$(circuitModelNames[i]) >>>>> ) for i = 1:length(circuitModelNames) ]...) |> esc >>>>> >>>>> end >>>>> >>>>> >>>>> julia> macroexpand (:(@fetch model)) >>>>> >>>>> :(begin >>>>> >>>>> v1 = model.v1 >>>>> >>>>> v5 = model.v5 >>>>> >>>>> v7 = model.v7 >>>>> >>>>> v2 = model.v2 >>>>> >>>>> v3 = model.v3 >>>>> >>>>> v4 = model.v4 >>>>> >>>>> v9 = model.v9 >>>>> >>>>> v12 = model.v12 >>>>> >>>>> v15 = model.v15 >>>>> >>>>> v18 = model.v18 >>>>> >>>>> v19 = model.v19 >>>>> >>>>> v20 = model.v20 >>>>> >>>>> v21 = model.v21 >>>>> >>>>> v8 = model.v8 >>>>> >>>>> v22 = model.v22 >>>>> >>>>> v23 = model.v23 >>>>> >>>>> v24 = model.v24 >>>>> >>>>> i1 = model.i1 >>>>> >>>>> i2 = model.i2 >>>>> >>>>> i3 = model.i3 >>>>> >>>>> i4 = model.i4 >>>>> >>>>> i5 = model.i5 >>>>> >>>>> i6 = model.i6 >>>>> >>>>> i7 = model.i7 >>>>> >>>>> ic1eq = model.ic1eq >>>>> >>>>> ic2eq = model.ic2eq >>>>> >>>>> ic3eq = model.ic3eq >>>>> >>>>> ic4eq = model.ic4eq >>>>> >>>>> ic5eq = model.ic5eq >>>>> >>>>> ic6eq = model.ic6eq >>>>> >>>>> ic7eq = model.ic7eq >>>>> >>>>> ic8eq = model.ic8eq >>>>> >>>>> sr = model.sr >>>>> >>>>> srinv = model.srinv >>>>> >>>>> pi = model.pi >>>>> >>>>> gmin = model.gmin >>>>> >>>>> is1 = model.is1 >>>>> >>>>> nvtf1 = model.nvtf1 >>>>> >>>>> is2 = model.is2 >>>>> >>>>> nvtf2 = model.nvtf2 >>>>> >>>>> nvtinvf1 = model.nvtinvf1 >>>>> >>>>> vcritf1 = model.vcritf1 >>>>> >>>>> nvtinvf2 = model.nvtinvf2 >>>>> >>>>> vcritf2 = model.vcritf2 >>>>> >>>>> gc1 = model.gc1 >>>>> >>>>> gr1 = model.gr1 >>>>> >>>>> gr2 = model.gr2 >>>>> >>>>> itxr2 = model.itxr2 >>>>> >>>>> gc2 = model.gc2 >>>>> >>>>> gc3 = model.gc3 >>>>> >>>>> gc4 = model.gc4 >>>>> >>>>> gc5 = model.gc5 >>>>> >>>>> gr7 = model.gr7 >>>>> >>>>> gc6 = model.gc6 >>>>> >>>>> gr3 = model.gr3 >>>>> >>>>> itxr3 = model.itxr3 >>>>> >>>>> gc7 = model.gc7 >>>>> >>>>> gr4 = model.gr4 >>>>> >>>>> gc8 = model.gc8 >>>>> >>>>> gr5 = model.gr5 >>>>> >>>>> vpos = model.vpos >>>>> >>>>> vneg = model.vneg >>>>> >>>>> gin = model.gin >>>>> >>>>> gininv = model.gininv >>>>> >>>>> vposcap = model.vposcap >>>>> >>>>> vnegcap = model.vnegcap >>>>> >>>>> ginotacore = model.ginotacore >>>>> >>>>> ginotares = model.ginotares >>>>> >>>>> ginotacoreinv = model.ginotacoreinv >>>>> >>>>> ginotaresinv = model.ginotaresinv >>>>> >>>>> vc3lo = model.vc3lo >>>>> >>>>> vc3hi = model.vc3hi >>>>> >>>>> a4a4c = model.a4a4c >>>>> >>>>> a5a5c = model.a5a5c >>>>> >>>>> a6a6c = model.a6a6c >>>>> >>>>> a14a14c = model.a14a14c >>>>> >>>>> a16a16c = model.a16a16c >>>>> >>>>> a17a17c = model.a17a17c >>>>> >>>>> a17a17nrmc = model.a17a17nrmc >>>>> >>>>> a12a17c = model.a12a17c >>>>> >>>>> a16a16nrmc = model.a16a16nrmc >>>>> >>>>> a15a16c = model.a15a16c >>>>> >>>>> a14a14nrmc = model.a14a14nrmc >>>>> >>>>> a13a14c = model.a13a14c >>>>> >>>>> a6a14c = model.a6a14c >>>>> >>>>> a13a6c = model.a13a6c >>>>> >>>>> a5a5nrmc = model.a5a5nrmc >>>>> >>>>> a4a5c = model.a4a5c >>>>> >>>>> a2a5c = model.a2a5c >>>>> >>>>> a2a4c = model.a2a4c >>>>> >>>>> a4a4nrmc = model.a4a4nrmc >>>>> >>>>> a1a4c = model.a1a4c >>>>> >>>>> v5c = model.v5c >>>>> >>>>> v7c = model.v7c >>>>> >>>>> end) >>>>> >>>>>
