Expression.Callbacks (expression v2.41.4)
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
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.
@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:
- The function name as is
- The function name with an underscore suffix if the function name is a reserved word
- The function name suffixed with
_vargs
if the takes a variable set of arguments