comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Generators/coroutines in future Ada?
Date: Wed, 12 Jul 2017 01:57:58 -0700 (PDT)
Date: 2017-07-12T01:57:58-07:00	[thread overview]
Message-ID: <f573b3ad-db2d-42f5-9b53-cfed4b877519@googlegroups.com> (raw)
In-Reply-To: <ok26bp$lt4$1@dont-email.me>

> Taking the example from Wikipedia:
> 
> function startAt(x)
>    function incrementBy(y)
>        return x + y
>    return incrementBy
> 
> variable closure1 = startAt(1)
> variable closure2 = startAt(5)

Note that this example does not exploit (pun intended) the fact that such variables can be created dynamically, where their exact number is not known until the program is run. Imagine an array (of length determined at run-time) of such generators. This shows that static approach of Ada is not always convenient and is not applicable to every problem.

Dmitry is right that generators can be replaced with functions that operate on explicit state, but generators are useful, because they have the same interface as stateless functions[*] and can be used as arguments in higher-level generics that accept "callable" entities without caring about whether they are stateful or not[**]. Functional languages (or at least those that claim to have some features from functional programming) are convenient for gluing stuff together this way, with obvious compromises in other areas.

[*] That is, there is some commonality between stateless and stateful functions and it might be useful to capture this commonality in some programming concept that is not present in Ada.

[**] C++ relies on such constructs in the STL library (and many others), but calls them "functors" instead. That is, a generator can be implemented as a stateful functor (and they can be created dynamically). Whether they are used wisely is another story.

-- 
Maciej Sobczak * http://www.inspirel.com

      parent reply	other threads:[~2017-07-12  8:57 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-09 20:19 Generators/coroutines in future Ada? Victor Porton
2017-07-09 21:28 ` Dennis Lee Bieber
2017-07-09 23:56   ` Victor Porton
2017-07-10  7:33   ` Dmitry A. Kazakov
2017-07-10 13:38 ` Victor Porton
2017-07-10 17:01   ` Paul Rubin
2017-07-10 21:24     ` Victor Porton
2017-07-12 17:09       ` Paul Rubin
2017-07-12 17:39         ` Victor Porton
2017-07-13  6:35           ` Paul Rubin
2017-07-11  9:42   ` J-P. Rosen
2017-07-11 12:52     ` Victor Porton
2017-07-11 13:01       ` Victor Porton
2017-07-11 13:26         ` J-P. Rosen
2017-07-11 16:04           ` Dennis Lee Bieber
2017-07-11 16:59           ` Dmitry A. Kazakov
2017-07-11 19:52             ` Pascal Obry
2017-07-11 20:18               ` Dmitry A. Kazakov
2017-07-11 18:36           ` Victor Porton
2017-07-11 19:22             ` J-P. Rosen
2017-07-11 20:25               ` Dmitry A. Kazakov
2017-07-11 23:19                 ` Victor Porton
2017-07-12  4:54                   ` J-P. Rosen
2017-07-12 13:07                     ` Victor Porton
2017-07-12 13:38                       ` Dmitry A. Kazakov
2017-07-12  5:35                   ` Randy Brukardt
2017-07-12  7:27                     ` Dmitry A. Kazakov
2017-07-12 22:47                     ` Shark8
2017-07-16 13:11                       ` Robert Eachus
2017-07-17 23:54                       ` Randy Brukardt
2017-07-18  7:38                         ` Dmitry A. Kazakov
2017-07-12  7:19                   ` Dmitry A. Kazakov
2017-07-12  6:35                 ` G.B.
2017-07-12  7:34                   ` Dmitry A. Kazakov
2017-07-12 20:49                     ` G.B.
2017-07-13  8:18                       ` Dmitry A. Kazakov
2017-07-12 17:34           ` Paul Rubin
2017-07-11 19:27         ` Simon Wright
2017-07-12  5:42     ` darkestkhan
2017-07-12  8:57     ` Maciej Sobczak [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox