View Source Defconstant (defconstant v1.0.0)
Helper functions for defining constant values in your modules.
Usage
defmodule Foo do
import Defconstant
defconst comptime do
# This will be evaulated at compile time
Enum.sum([
0, 2, 3, 4, 5, 6, 8, 12, 30, 32, 33, 34, 35, 36, 38, 40, 42, 43, 44, 45,
46, 48, 50, 52, 53, 54, 55, 56, 58, 60, 62, 63, 64, 65, 66, 68, 80, 82,
83, 84, 85, 86, 88
])
end
defonce runtime do
2 * 1068 + 1
end
end
Summary
Functions
Defines function that will be evaulated once, in compile time, and will return computation result.
Defines function that will be evaulated once, in runtime, and will cache the result.
Functions
Defines function that will be evaulated once, in compile time, and will return computation result.
Defined function can only be 0-ary.
Example:
defmodule MyConstants do
import Defconstant
defconst the_answer, do: 42
def my_func do
the_answer() * 2 # returns 84
end
end
Defines function that will be evaulated once, in runtime, and will cache the result.
Defined function can only be 0-ary.