CarlosHSF
How to identify an AST node as a function call?
I’m trying to identify function calls. My current solution seems to be working, but I’m not sure what are the edge cases I should test for and I imagine there’s a better solution.
So far I determine a node is a function call if it is a triple, it’s third element is a list and it is not a special form.
So this {:foo, [], []} would be a function call, but this {:{}, [], []} wouldn’t and neither would this {:foo, [], nil}.
The code:
# for functions calls or special forms with the same structure
defmacro foo({call, _meta, args}) when is_list(args) do
if Macro.special_form?(call, length(args)) do
# do stuff if it ISN'T a function call
else
# do stuff if it IS a function call
end
end
# for literals and variables
defmacro foo(node) do
# do stuff if it ISN'T a function call
end
If you see any errors or know a better solution your help would be greatly appreciated!
Most Liked
benwilson512
Hey @CarlosHSF to my knowledge this is roughly correct, but it’s also worth noting that it can’t distinguish between a macro call and a function call as, at an ast level at least, they are identical. You’ll also have to decide how you want to handle things like apply/3.







