Hello,
(Apologies for the long post, issue is not that complex, I was just trying to be descriptive to make understanding it easier)
As I understand it, metaprogramming is the tool that will help me achieve my objective.
Specifically, what I am trying to accomplish is to write a macro that returns a string or some other sequence of characters that are not actually a string but rather are code and I can directly plop that code as the input to another function, not in the sense that I am defining a variable and passing in that variable to the function but rather that the programming is returning what I would be writing myself into the function.
I will provide an example
@macro foo()
#some code
end
vcat(@macro foo())
so say for example I wanted vcat to concatenate an arbitrary but specific number of arguments that all have different names.
Thus, I could not just return them as an array because vcat will not operate on an array of inputs. I could provide the input as a tuple of arrays but that fails for my purposes because what I am trying to vertically concatenate are functions and not arrays and thus I need to pass them in within the context of an anonymous function. Thus, I have to pass in the function names with (x) appended onto the end of them.
For example, it would need to look like that:
fooy = x -> vcat(foo1(x), foo2(x))
Now it would be easy to use a for loop and construct a string that exactly replicates the input that I would want in vcat(here) but obviously such a function would return a string and not code that I can just pass into the function in the same way as if I were to manually type that code into the parameter of vcat. This is why I suspect I need to use metaprogramming. As understand it, it would allow me to do things like this where I can have results that are julia code and not types like Strings, etc.
Is there anyone that knows how to do this?
so far I have used the following code (note this is a bit simplified so that it is easier to follow):
#the function I am trying to vertically concatenate
circ(x) = x./sqrt(sum(x .* x))
for i in 1:n_circs1
@eval $(Symbol("encoderbottle_$i")) = circ
end
and this code creates a variables encoderbottle_1 to encoderbottle_n_circs1 (where n_circs1 is an integer and not actually n_circs1).
What this code means is that I dont have to worry about createing the variables, I just need to write a macro that creates the following Julia code:
encoderbottle_1(x), encoderbottle_2(x), ... encoderbottle_n_circs1(x)
(obviously without the … and the appropriate remainder of the pattern in place)
and then I can just plop that julia code (not plop is my word and not a technical term i dont think) into the args for the vcat function.
Any help with how to do this would be much appreciated since I still do not fully understand macros in Julia.
Thank you.