Eliminate assert and lazy from D?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Oct 12 22:44:05 PDT 2009
Robert Jacques wrote:
> On Tue, 13 Oct 2009 00:33:57 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> Right now, the language has enough power to express assert as a
>> library function, as opposed to a primitive construct. (See e.g.
>> enforce.) I think it would be good to relegate assert to object.d.
>>
>> This also brings up "lazy", which seems to be quite botched. Are there
>> suggestions on how to replicate its functionality in a different way?
>> I even seem to recall lazy was discussed as a disadvantage in the
>> recent dialog on reddit, see
>>
>> http://www.reddit.com/r/programming/comments/9qf8i/i_wrote_some_d_today_and_its_completely_blowing/
>>
>>
>> I personally believe it's useful to be able to pass an unevaluated
>> expression into a function, for example assert and enforce themselves
>> use that.
>>
>> But let's open this for discussion: should assert and/or lazy be
>> removed? If not, why not? It yes, why? How can we replicate their
>> functionality?
>>
>>
>> Andrei
>
> Well, a lazy 'variable' is really a delegate of an expression, so
> implicit conversion of an expression to a delegate would be one way to
> remove lazy. (Not sure how practical/easy that is though)
Yah, that's how the feature was initially proposed.
> And then assert (I think) becomes
>
> void assert( bool delegate() expr, string delegate() msg ) {
> debug {
> if(!expr)
> throw new Exception(msg);
> }
> }
>
It's simpler actually:
debug void assert(T)( T expr, string delegate() msg ) {
if(!expr)
throw new Exception(msg);
}
else void assert(T)( T delegate(), string delegate() ) {
}
Hm, actually it's more complicated than your version :o).
Andrei
More information about the Digitalmars-d
mailing list