[Issue 5906] Just pre-conditions at compile-time when arguments are static

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 24 02:48:32 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5906



--- Comment #1 from bearophile_hugs at eml.cc 2012-12-24 02:47:41 PST ---
In Ada 2012 there is a "Static_Predicate" aspect:
http://www.ada-auth.org/standards/12rm/html/RM-3-2-4.html

It allows to attach a compile-time predicate that verifies the validity of a
subtype (there is also "Dynamic_Predicate"). 


So an idea to reduce the problems underlined by Walter is to add "static
preconditions" (note the static before the "in" (currently this code is not
allowed):


import std.ascii: isDigit;
int foo(string text, int x)
static in {
    assert(x >= 0 && x < text.length);
    foreach (c; text[0 .. x])
        assert(isDigit(c));
} body {
    return 0;
}

void main() {}



Adding "static" to a precondition means the compiler will try to run the
precondition at compile-time where possible, and at run-time where it's not
possible. So the not-static preconditions are run only at run time, avoiding
unwanted explosions of compilation times.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list