Expression.Callbacks (expression v2.33.1)

Use this module to implement one's own callbacks. The standard callbacks available are implemented in Expression.Callbacks.Standard.

defmodule MyCallbacks do
  use Expression.Callbacks

  @doc """
  Roll a dice and randomly return a number between 1 and 6.
  """
  def dice_roll(ctx) do
    Enum.random(1..6)
  end

end

Summary

Functions

Convert a string function name into an atom meant to handle that function

Handle a function call while evaluating the AST.

Functions

Link to this function

atom_function_name(function_name)

Convert a string function name into an atom meant to handle that function

Reserved words such as and, if, and or are automatically suffixed with an _ underscore.

Link to this function

handle(module \\ Standard, function_name, arguments, context)

@spec handle(
  module :: module(),
  function_name :: binary(),
  arguments :: [any()],
  context :: map()
) ::
  {:ok, any()} | {:error, :not_implemented}

Handle a function call while evaluating the AST.

Handlers in this module are either:

  1. The function name as is
  2. The function name with an underscore suffix if the function name is a reserved word
  3. The function name suffixed with _vargs if the takes a variable set of arguments
Link to this function

implements(module \\ Standard, function_name, arguments)