I am fairly new to Julia, so apologies for any misunderstandings of the language I may have. I have mostly used Python recently, and made heavy use of SymPy and its code generation features, and it seems like Julia with its metaprogramming features is built for writing code in exactly the kind of style I like.
In particular, I want to construct block matrices in Julia from a set of smaller building blocks with some different operations in between. For debugging purposes and because the various intermediate matrices are used in other calculations, I want to keep them as expressions containing variables, such that I can quickly loop over and test different different inputs, without wrapping everything in a function.
Now, for a minimal case study, say I have two expressions mat1 = :a
and mat2 = :b
that I want to combine to form a new, third expression:
mat3 = :($mat1 + $mat2)
The above method works fine until I modify mat1
and mat2
, in which case I have to re-evaluate mat3
in order to reflect this update. This is caused, I presume, by the fact that $mat1 + $mat2
is not passing mat1
and mat2
by reference, but rather interpolates the expressions inside at the time of evaluation of that line. The behaviour I want to achieve is that mat1
and mat2
are not inserted until I call eval(mat3)
, preferably with minimal boilerplate.
Is it possible to achieve this in a handy syntax?
mat3
will reflect the mutation ofmat1
andmat2
, but not rebinding ofmat1
andmat2
. It is important to understand the distinction between mutation and rebinding. – Fengyang Wang