simpler v0.2.1 Simpler.Contract
Very basic Design-by-Contract support.
precondition op_one > op_two
postcondition result > 0
def subtract(op_one, op_two) do
op_one - op_two
end
You can have any number of pre- and postconditions, and they will apply to
any head of the function that follows. Postconditions can use the variable
result which will hold the result of the function (so, err, yeah - the
Simpler.Contract.def macro is not hygienic - don’t use result in your
own code. Although it usually should not conflict as this result is only
assigned and used after the last line of your method body’s code).
Summary
Functions
Override of def that will run current contract definitions
Define a postcondition. A special variable result holds the result
of the function. If the postcondition doesn’t hold, raise an error
Define a precondition. Argument names should be availablable in any function head’s arguments. If the precondition doesn’t hold, raise an error
Functions
Define a postcondition. A special variable result holds the result
of the function. If the postcondition doesn’t hold, raise an error.