Curious thoughts, regarding functional programming
Simen Kjaeraas
simen.kjaras at gmail.com
Wed Oct 12 10:40:35 PDT 2011
On Wed, 12 Oct 2011 19:00:56 +0200, Jacob Carlborg <doob at me.com> wrote:
> On 2011-10-12 18:18, Gor Gyolchanyan wrote:
>> You never know when exactly and in which conditions will that delegate
>> get called. You can't decide to quit something you don't know anything
>> about.
>
> If a function implements something similar to a loop I would like to be
> able to abort it with a return just as you can with a loop built into
> the language.
>
> void loop (void delegate () dg)
> {
> while (true)
> dg();
> }
>
> loop
> {
> if (someCondition)
> return; // stops the loop
> }
However, a lot of code using this syntax would be more complex than what
you indicate. Should it work simply as a break in the loop? What if it
is a recursive function? There is a reason why opApply is designed the
way it is.
--
Simen
More information about the Digitalmars-d
mailing list