On a more general note, I am thinking that with a bit of cleanup, this code could make a good Julia metaprogramming example, especially since I haven't seen many of those around :)
//A On Saturday, August 30, 2014 10:52:49 AM UTC+2, Andrei Berceanu wrote: > > This is what I came up with for the full matrix calculation: > > https://github.com/berceanu/notebooks/blob/master/julia/macros.ipynb > > I now have a macro for the elements of M, another for the elements of Q > and yet another for the elements of L. In the end I define the genmatL > function which loops over the dimensions of L and calculates all the matrix > elements. Does this look sound to you? > > A few things that are still unclear: > 1. Can this approach be optimized further? I can't help the feeling that > it contains a fair amount of redundancy, especially looking at the quote > $var end kind of expressions. I can replace the macros with functions as > you suggest, but then it's not clear to me when to use a function and when > a macro. > 2. I would like to see the functional form of the full matrix L (not just > element by element, but the whole matrix of expressions), in terms of the > functions \epsilon, \gamma and X. I tried with macroexpand acting on > genmatL, but that doesn't seem to work. This is basically just to convince > myself that the approach indeed works as intended. > > Thanks again! > > On Friday, August 29, 2014 10:14:10 PM UTC+2, Steven G. Johnson wrote: >> >> I think you want >> >> quote >> @M($i,$j, $ε1, ....) >> end >> >> in order for your L macro to return an expression (that in turn calls the >> M macro). >> >> Macros are not functions. When you call @M(i,j,...), it doesn't pass the >> *value* of the arguments i,j, etcetera, it passes the symbolic expressions >> :i, :j, and so on. >> >> Of course, if you are only calling M from inside another macro, it is >> perfectly valid to just change M from a macro to an ordinary function >> (returning an expression) ... just change "macro" to "function" in the >> definition of M, and call it without the "@" inside L. >> >
