compute-it
compute-it is a crate that provides a lazy evaluation of variables, with dependencies.
Development occurs in the dev/1 branch.
Example of use
compute-it can be used to create computation with a static structure. In such use case, the structure of the computation does not changes, only the value of the variables.
use *;
let v1 = new;
let v2 = new;
let v3 = new;
// Create a new computation `c1` with `v1`, `v2` and `v3` as variables.
let c1 = new;
println!;
// Change in `v1` change the result of `c1`.
v1.set;
println!;
Computation can also be used as input to other computation, and give access to intermediary results:
use *;
let v1 = new;
let v2 = new;
let v3 = new;
// Create a new computation `c1` with `v1` and `v2` as variables.
let c1 = new;
println!;
// Create a new computation `c2` which uses the result of `c1` and the variable `v3`.
let c2 = new;
println!;
// Change in the value `v1` also changes the result of `c2`.
v1.set;
println!;
println!;
compute-it can be used to create computation with a dynamic structure. In such use case, the list of variables and their value can be changed during runtime.
use *;
let v1 = new;
let v2 = new;
let v3 = new;
// Create a new computation `c1` with `v1` and `v2` as initial set of variables.
let mut c1 = new;
println!;
// Add `v3` to the set of varibles.
c1.push;
println!;
// Remove `v2` to the set of varibles.
c1.remove;
println!;
// Change the value of `v1`
v1.set;
println!;
Variables can also be grouped:
use *;
let v1: = 0.into;
let v2: = 1.into;
let v3: = 2.into;
/// Create a vec computation where the vector is made of a tuple of reference to i32 and u32 variables.
let mut c1 = new;
Sometime it can be needed to change the input of a computation to a different variable, without changing the rest of the structure of the computation graph. We can use Reference for that purpose:
use *;
let v1: = 1.into;
let v2: = 2.into;
let mut ref1 = new;
// `c1` is initialized to use `v1` as input.
let c1 = new;
println!;
// After this call `c1` will use `v2` as input.
ref1.replace;
println!;