Common use of Dependent Contracts Clause in Contracts

Dependent Contracts. ‌ A dependent contract is a special function contact where the range contract depends on the function arguments. In TreatJS, dependent contracts are created using contract constructors that are invoked with the caller’s arguments. The constructor binds the arguments values and returns a contract for the range of that function. The following example demonstrates the construction of a dependent contract that specifies that a function sort has to return an array of the same length as its input array. The constructor Contract.Dependent can either be called with a single JavaScript function or with a contract constructor. Calling the constructor with function internally converts the function to a contract constructor. let sort = Contract.assert(function sort(input, compareFunction) { /* not specified in detail */ }, Contract.Dependent(function(input, compareFunction) { return Contract.Base(function(output) { }); });

Appears in 2 contracts

Sources: Dissertation, Dissertation