Computations
DataAxesFormats.Computations
—
Module
Support writing "well-behaved" computations. Such computations declare a
Contract
describing their inputs and outputs. This is enforced, so that the implementation need not worry about missing inputs, and the caller can rely on the results. It is also self-documenting, so the generated documentation is always contains a clear up-to-date description of the contract.
DataAxesFormats.Computations.@computation
—
Macro
@computation Contract(...) function something(daf::DafWriter, ...)
return ...
end
@computation Contract(...) Contract(name = "second" ...) function something(
first::DafReader/DafWriter; second::DafReader/DafWriter, ...
)
return ...
end
@computation Contract(...) Contract(name = "second", ...) Contract(name = "third", ...) function something(
first::DafReader/DafWriter; second::DafReader/DafWriter, third::DafReader/DafWriter, ...
)
return ...
end
Mark a function as a
Daf
computation. This has the following effects:
- It has the same effect as
@documented, that is, allows usingDEFAULTin the documentation string, and usingfunction_defaultto access the default value of named parameters. - It verifies that the
Dafdata satisfies theContract, when the computation is invoked and when it is complete (usingverify_inputandverify_output). - It stashes the contract(s) (if any) in a global variable. This allows expanding
CONTRACTin the documentation string (for a single contract case), orCONTRACT1andCONTRACT2(for the dual contract case), orCONTRACT1andCONTRACT2andCONTRACT3(for the triple contract case).
DataAxesFormats.Computations.function_contract
—
Function
function_contract(func::Function[, index::Integer = 1])::Contract
Access the contract of a function annotated by
@computation
. By default the first contract is returned. If the
@computation
has two contracts, you can specify the
index
of the contract to return.
DataAxesFormats.Computations.CONTRACT
—
Constant
When using
@computation
:
'''
...
# Contract
...
$(CONTRACT)
...
'''
@computation Contract(...) function something(daf::DafWriter, ...)
return ...
end
Then
$(CONTRACT)
will be expanded with a description of the
Contract
. This is based on
DocStringExtensions
.
The first argument of the function must be a
DafWriter
, which the contract will be applied to.
DataAxesFormats.Computations.CONTRACT1
—
Constant
Same as
CONTRACT
, but reference the contract for the 1st
Daf
argument for a
@computation
with two such arguments.
DataAxesFormats.Computations.CONTRACT2
—
Constant
Same as
CONTRACT
, but reference the contract for the 2nd
Daf
argument for a
@computation
with two such arguments.
DataAxesFormats.Computations.CONTRACT3
—
Constant
Same as
CONTRACT2
, but reference the contract for the 3rd
Daf
argument for a
@computation
with three such arguments.