[fpc-devel] Re: Testing for..in feature

Alexander Klenin klenin at gmail.com
Thu Nov 5 05:44:44 CET 2009


On Thu, Nov 5, 2009 at 14:39, Paul Ishenin <ip at kmiac.ru> wrote:
> Alexander Klenin wrote:

>>> 2) skip any compiler code modifications since the next code still works
>>> and
>>> outputs 5 numbers:
>>> type T = (a1, b1=5);
>>> var
>>>  ch: T;
>>> begin
>>>  for ch in T do
>>>   WriteLn(Ord(ch)); // <- note Ord() here
>>> end
>>
>> What are these numbers? (Sorry, I am at work, can not test from here).
>> I would be surprised if they are "0 5".
>
> 0, 1, 2, 3, 4, 5

Oh. I think it is better to generate error than to output such nonsense.

>>> 4) write 2 magic functions: one to get the next enum value, one to get
>>> the
>>> previos enum value and implement a special handling in the for-in loop
>>> for
>>> such arrays
>>
>> I always thought Succ/Pred are exactly such magic functions ;-)
>
> yes, forgot about them.

So, I vote for converting "for i in Enum do" into

while ... do
  ...
  i := Succ(i);
end;

This will automatically fail for non-consecutive enums, which is fine for now.
If later it will be decided to extend Succ/Pred functions to handle
non-consecutive enums,
for..in loops will also start working for them.

-- 
Alexander S. Klenin



More information about the fpc-devel mailing list