Postfix (postfix v1.2.339)

Evaluator of terms using postfix notation

Link to this section Summary

Functions

Evaluate a list of values and functions

Evaluate a list of values and functions using a stack.

Link to this section Functions

@spec eval([term()]) :: {:ok, term()} | {:error, any()}

Evaluate a list of values and functions

iex> Postfix.eval([2, 3, &*/2, 4, &+/2])
{:ok, 10}

iex> Postfix.eval([1, 2, &-/2])
{:ok, -1}

Operands are given to the function in the natural left-to-right order. All operands are consumed by the function - the arity is not checked.

Link to this function

eval_stack(terms)

@spec eval_stack([term()]) :: {:ok, term()} | {:error, any()}

Evaluate a list of values and functions using a stack.

See Postfix.Stack.eval/1