[phobos] Pureness of enforce()

Steve Schveighoffer schveiguy at yahoo.com
Tue Nov 9 05:01:56 PST 2010


A while back, I suggested changing enforce to not take a lazy argument.  In my 
investigation 90% of uses of enforce do not need the lazy argument (because the 
string is constructed at compile-time).

My suggestion is to remove lazy from enforce, mark it as pure, and create a 
lazyEnforce that takes a lazy argument for use in the few places it's needed.

-Steve



----- Original Message ----
> From: Lars Tandle Kyllingstad <lars at kyllingen.net>
> To: Phobos mailing list <phobos at puremagic.com>
> Sent: Tue, November 9, 2010 6:21:38 AM
> Subject: [phobos] Pureness of enforce()
> 
> enforce(x) is basically a substitute for
> 
>   if (x) throw new  Exception;
> 
> which doesn't violate the purity rules.  It is not  possible to annotate
> enforce() with 'pure', however, because it takes a lazy  parameter, which
> is just shorthand for a (possibly impure)  delegate.
> 
> enforce() is used virtually everywhere in Phobos, and this  means that a
> lot of functions that could otherwise be marked as pure,  currently
> can't.
> 
> One example is std.conv.to(), which should definitely be  pure.  (In
> fact, I tried marking it as such, which is what got me  thinking about
> this in the first place.)
> 
> What to  do?
> 
> -Lars
> 
> _______________________________________________
> phobos  mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> 


      


More information about the phobos mailing list