Idea: function contracts + CTFE

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Jun 20 14:42:24 PDT 2008


"Yigal Chripun" <yigal100 at gmail.com> wrote in message 
news:g3h56u$2evu$1 at digitalmars.com...

> Sounds totally unnecessary.
> if you pass 30 to the above fork you already know that it's not between
> 0 and 20 (that is if you finished 2nd grade of school). you need help
> from the compiler when you do not know what x is, i.e. in run-time.
> I don't see any practical benefits to this outside of meta-programming
> and there I'd expect the compiler to throw the assert error during
> compilation.

I'm suggesting this from the point of view of someone who writes libraries 
which have certain input restrictions.  I'd rather the errors about the 
inputs to a function happen at compile time than at some indefinite point in 
time at runtime.

> another issue is the removal of asserts in release mode. I'm not sure
> that asserts should only work in debug mode and personally would prefer
> to keep them in the released version. this probably should have a
> compiler flag to control it. I don't like DMD's release and debug modes
> at all and thing that the user should have a more fine grained control
> over compilation. GCC allows me to define what kinds of optimizations I
> want with a flag for each setting instead of a global release mode as
> defined by Walter.
> for example what if I'd like to compile my code with contracts and with
> array bounds checking removed? How do I accomplish that?

Totally agree.  It's funny -- DMDFE already has fine-grained control for 
contracts, asserts, bounds checking etc. but for some reason those options 
aren't exposed by the command-line compiler, they're all set as a chunk 
by -debug and -release. 





More information about the Digitalmars-d mailing list