Difference between revisions of "Talk:for-in loop"
(Proposed extensions - Select which enumerator to use) |
(Use NativeUInt type for temporary loop example as this is also defined in Delphi) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
== Proposed extensions - index == | == Proposed extensions - index == | ||
May be more pretty will python or php-like syntax <code>for ch[i] in s do Writeln(i, ': ', ch);</code> (see http://www.php2python.com/wiki/control-structures.foreach/ for reference) --[[User:Nashev|Nashev]] 18:43, 12 September 2011 (CEST) | May be more pretty will python or php-like syntax <code>for ch[i] in s do Writeln(i, ': ', ch);</code> (see http://www.php2python.com/wiki/control-structures.foreach/ for reference) --[[User:Nashev|Nashev]] 18:43, 12 September 2011 (CEST) | ||
+ | == Multiple enumerators for one class == | ||
+ | |||
+ | The underlying code causes a memory leak: | ||
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
+ | function TEnumerableTree.GetReverseEnumerator: TTreeReverseEnumerator; | ||
+ | begin | ||
+ | Result:=TTreeReverseEnumerator.Create(Self); | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | object created, but not destroyed |
Latest revision as of 20:48, 10 April 2021
Proposed extensions - Select which enumerator to use
Why so complicated syntax and new keyword using? Why do not just always use syntax like for x in <IEnumeratorExpression> do ...;
, as described in Variant3 and Variant4? In this case no need to introduce any FPC-specific operator (or just to describe default enumerator, to make text shorter?..), no need 'enumerator MoveNext' and 'enumerator Current' modifiers, because interface implementation already can be mapped to other methods... --Nashev 18:43, 12 September 2011 (CEST)
Proposed extensions - index
May be more pretty will python or php-like syntax for ch[i] in s do Writeln(i, ': ', ch);
(see http://www.php2python.com/wiki/control-structures.foreach/ for reference) --Nashev 18:43, 12 September 2011 (CEST)
Multiple enumerators for one class
The underlying code causes a memory leak:
function TEnumerableTree.GetReverseEnumerator: TTreeReverseEnumerator;
begin
Result:=TTreeReverseEnumerator.Create(Self);
end;
object created, but not destroyed