That is really nice. I see the 0.4 version also avoids the special syntax, so you can just treat fun() like an ordinary function. That's good for readability, plus it means I can share the same code with people who don't understand FastAnonymous by just dropping the @anon marker and leaving everything else unchanged.
On Monday, June 22, 2015 at 11:38:44 PM UTC-4, Tim Holy wrote: > > The implementation of FastAnonymous for julia 0.4 is radically different > from > the implementation for julia 0.3---they are truly two different packages > that > happen to have the same name. The version for 0.4 gives you the ability to > modify/own the parameters. That design is simply not possible with 0.3. > > --Tim > > On Monday, June 22, 2015 05:56:42 PM Andrew wrote: > > I think part of the reason I wanted to do this is because I used to code > in > > Java, and in Java it's common to encapsulate variables and methods > within > > an object, and then have the object's methods reference itself. I guess > > there's nothing stopping me from doing similar here, I could write > > something like > > > > function u(UF::UtilityFunction,consump,labor) > > sigmac = UF.sigmac > > sigmal = UF.sigmal > > psi = UF.psi > > consump.^(1-sigmac)/(1-sigmac) + > psi*(1-labor).^(1-sigmal)/(1-sigmal) > > end > > > > but this is sort of ugly, so I'd prefer to avoid explicitly passing any > > parameters, I also keep thinking that explicitly passing around > parameters > > should slow things down, so I've been reluctant to do it, but I just > tested > > it a bit. I haven't observed any performance loss. Perhaps I am > conditioned > > by MATLAB to avoid these things since it uses pass-by-value, so I > believe > > passing parameters makes copies there. Since Julia doesn't do this, > there > > shouldn't be a performance hit. > >
