Loop iterator - example.txt

kellywilson at nowhere.com kellywilson at nowhere.com
Sun Apr 30 03:34:09 PDT 2006


Hello all,

I agree with Kyle on this one as well. I have added the "retry" keyword to my
parser and it really amounts to the same thing as "continue". The only
difference would be if one were to restrict the "retry" keyword to work only
within the 'for' and 'foreach' loop constructs. This is a little tough to do
with the grammar (though it can be done in the semantic checking phase fairly
easily, I believe....Walter [or someone very familiar with the dmdfe] may have
to answer that one since my parser doesn't do semantic checking yet ;)

Anyways, easy to add keyword, but in the same place as "continue", so why do it?

My two cents,
Kelly Wilson 

In article <e31khr$6tg$1 at digitaldaemon.com>, Kyle Furlong says...
>
>Unknown W. Brackets wrote:
>> I would probably do something more like (assuming there is no other code 
>> but the tests):
>> 
>> int i = 0;
>> while (i < 10)
>> {
>>     if (string[i] == something)
>>     {
>>         i += some_other_function();
>>         continue;
>>     }
>>     else if (string[i] == something_else)
>>     {
>>         i += some_other_function2();
>>         continue;
>>     }
>> 
>>     // Otherwise, simply execute the "i++" and re-test
>>     i++;
>> }
>> 
>> I mean, while is a keyword too, isn't it?  I really am unclear on how 
>> it's any more obtuse... perhaps you're just not as used to it?
>> 
>> Do you cut everything, even cheese and fruit, with a steak knife? 
>> Perhaps you do.  But do master chefs as well?  Or do they use the right 
>> knives for the right purposes?
>> 
>> Actually, I might do this depending on the number of tests:
>> 
>> int pos = 0;
>> while (pos < string.length)
>> {
>>     switch (string[pos])
>>     {
>>     case something:
>>         pos += some_other_function(string[pos .. string.length]);
>>         break;
>> 
>>     case something_else:
>>         pos += some_other_function2(string[pos .. string.length]);
>>         break;
>> 
>>     default:
>>         pos++;
>>     }
>> }
>> 
>> Which, to me, seems much more clear than any "retry" would.  In fact, 
>> "retry" would seem incredibly unclear to me.  That's just me.  I don't 
>> see the concept of "retrying" anywhere.
>> 
>> The above code looks somewhat similar to code I've used in an xml 
>> document parser and a simple abbreviated xpath expression evaluator.  I 
>> can't even remember the last time I've used/wanted anything like a "retry".
>> 
>> Clearly, just my opinion.
>> 
>> -[Unknown]
>> 
>> 
>
>This, to me, is the right solution to the design pattern. No need for a 
>new keyword, and the functionality is clearly the same.





More information about the Digitalmars-d mailing list