Control Structures Proposal

downs default_357-line at yahoo.de
Wed Jul 25 02:25:45 PDT 2007


janderson wrote:
> downs wrote:
> 
>> janderson wrote:
>>
>>> For example you can currently do something like this in D (untested).
>>>
>>> For({int i=0;}, i!=0, {++i})
>>> ({
>>>
>>>
>>> });
>>
>>
>> You can do better.
>>
>> void For(lazy void ini, lazy bool cond, lazy void inc, void delegate() 
>> dg) {
>>         for (ini(); cond(); inc()) dg();
>> }
>>
>> import std.stdio;
>> void main() {
>>   int i=void;
>>   For (i=0, i<10, ++i, { writefln(i); });
>> }
>>
>> Yay for lazy void!
>>  --downs
> 
> 
> 
> I'm aware of this, I don't think its as close as having the delegate in 
> its own block.
> 
> -Joel
I actually agree with you; I also want some way to do custom blocks. All I'm saying is the existing 
way isn't entirely as bad as you described it. :p
  --downs



More information about the Digitalmars-d mailing list