I want pass a conditional statement within a function but not its evaluation result.
age(name, age, :age > 10)
def age(name, age, condition) do
quote do
unquote(condition)
end
I need to get the AST of the condition but right now it gives true
Thanks
It seems you should use defmacro
and not def
here.
cmo
September 30, 2022, 10:49am
3
Silly question, you dont want to pass a function? e.g. age(name, age, fn age -> age > 10 end)
4 Likes
defmacro
seems like a better option but i am not able to handle them in unit tests. If i have multiple tests and i want to run a single test then it runs all the macros called in all tests.
i don’t know if can convert the lambda function to AST.
Not sure you need to convert a closure to AST. You can just make your code accept a closure (lambda) and not do macro magic.
1 Like