erlangelixiraritypattern-guards

Erlang/Elixir guards and arity


Is there a way to see a function's guards without seeing the source code?

Given an example function (in Elixir):

def divide(x, y) when y != 0 do
  x / y
end

How would one figure out that there is a guard on divide/2 without access to the source code, and how would one find info about that guard or what that guard expects for a pattern match?

I was watching a talk by Chris McCord (creator of Elixir's Phoenix Framework) from Ruby Conf 2014. During the talk Chris was describing guards and someone asked if there was a way to inspect a function that would show the function's guards.

This is the question from the talk:

https://www.youtube.com/watch?v=5kYmOyJjGDM&t=5188

The question is asked shortly after the video's t= time.


Solution

  • Currently it is not possible to introspect this information without looking at the source.