[fpc-pascal] Optional param modifier
Martin Frb
lazarus at mfriebe.de
Mon Apr 15 01:08:26 CEST 2019
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.
More information about the fpc-pascal
mailing list