No idea, but a thought: wouldn't be too bad to have a @magic macro applied to the for loop - would even be kind of a warning to the reader that macro shenanigans are coming up.
On Thursday, October 23, 2014 5:18:27 PM UTC-4, Simon Byrne wrote: > > Is it possible to determine whether or not it is the first pass of a loop > entirely from within the loop, i.e. without adding extra statements outside > the loop? > > The context is that I've been thinking about how to avoid reallocating > arrays on each loop, for instance something like this will reallocate a > bunch of arrays on each iteration: > > X = starting_value > for i = 1:10 > # update A, B, U > ... > X += d * ((A+c*B) \ U) > end > > What I'd like to do is simply place a macro statement such as: > > X = starting_value > for i = 1:10 > # update A, B, U > ... > @reuse X += d * ((A+c*B) \ U) > end > > which would: > 1) On the first pass, break out all the computations and create bindings > to the intermediate arrays > 2) On every subsequent pass, reuse the intermediate arrays. > > Now I have some rough infrastructure for (2) in InplaceOps.jl, but I have > no idea how to determine whether or not I'm on the first pass, without > allocating variables outside the loop (which seems to be impossible from a > macro invoked inside the loop). Any ideas? > > Simon >
