Given this sym_list, I’d like to automatically generate a function that plugs the values denoted by the symbols ( where p could be a NamedTuple or struct, for example) into a vector:
function flatten(p)
return [p.a, p.b, p.c]
end
I’m stuck at synthesizing the inner part of the vector brackets:
function gen_flatten(sym_list)
flatten_sym = gensym("flatten")
func = quote
function $flatten_sym(p)
return [
# What to put here?
]
end
end
return eval(func)
end
I’ve tried splatting sym_list (i.e., put $(sym_list...) instead of the comment above) since that also works for calling functions. However, it didn’t work in this case and produced a syntax error:
Thanks for the suggestion. Unfortunately, it doesn’t fit my needs since no function is generated.
I am parsing a domain specific language and need to generate some code in order to use a Julia library / framework. Instead of creating some .jl file, I thought: Why not directly generate and eval() the Expressions?