GVA (global_variable v0.1.1) View Source

Global VAriable utilities.

All commands are prefixed with the letter g to prevent any clash with future Kernel functions. To use it in your script be sure to run at least Elixir 1.12 then import functions like the following:

Mix.install([:global_variable])
import GVA

An ETS table is used underneath meaning you can use any funky tricks to manipulate it data, pattern match and so on.

No variable table is created by default, you have to do it by yourself.

Examples

Mix.install([:global_variable])
import GVA

gnew :var
gput :var, :answer, 42
gget :var, :answer # 42
gget_and_update :var, :answer, fn x -> 1 + x end # 43

Link to this section Summary

Functions

Get an variable's value from a table by it's key.

Get and update a variable from a table by a function. Operation is probably not atomic and won't save you from race condition. (are you sure to write a script if you have these requirements?)

Create a new table to hold your variables. A table can hold as much variables (and associated data) as your RAM allows you.

Put a value in a variable table.

Link to this section Functions

Link to this macro

gget(table, key)

View Source (macro)

Get an variable's value from a table by it's key.

Link to this macro

gget_and_update(table, key, function)

View Source (macro)

Get and update a variable from a table by a function. Operation is probably not atomic and won't save you from race condition. (are you sure to write a script if you have these requirements?)

function must be a function with an arity of 1.

Create a new table to hold your variables. A table can hold as much variables (and associated data) as your RAM allows you.

Link to this macro

gput(table, key, value)

View Source (macro)

Put a value in a variable table.