Passing conditional statement as an argument

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

I need to get the AST of the condition but right now it gives true


It seems you should use defmacro and not def here.

Silly question, you dont want to pass a function? e.g. age(name, age, fn age -> age > 10 end)


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

yeah, that makes sense.