On 15/04/2019 00:53, Ryan Joseph wrote:
Here’s what I imagine that would look like: procedure CreateHero (name: string; hp: integer); requires name <> ''; (hp > 0) and (hp < 100); begin // compilers parses the conditions and inserts as if statements: // if name <> ‘’ then // assert(‘condition "name <> ‘'" for CreateHero failed’); // if (hp > 0) and (hp < 100) then // assert(‘condition "(hp > 0) and (hp < 100)" for CreateHero failed); end;
Almost. assert takes the condition itself assert(condition_that_must_be_true, 'error message') so it would be assert(name<>'', 'requires "name <> ''''" failed for CreateHero'); You can already insert such asserts yourself. assert exists. If you compile with -Sa then they are compiled in the code, otherwise not. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal