www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does D have anything like the generators of Python and some other

reply A D dev <addev dlang.com> writes:
Hi group,

Does D have anything like the generators of Python and some other 
languages?

Thanks.
Aug 29 2016
next sibling parent reply Cauterite <cauterite gmail.com> writes:
On Monday, 29 August 2016 at 21:24:52 UTC, A D dev wrote:
 Hi group,

 Does D have anything like the generators of Python and some 
 other languages?

 Thanks.
Ranges serve some of the purposes that generators are often used for: http://dlang.org/phobos/std_range.html But you can of course make true coroutine-based generators with fibres: http://dlang.org/phobos/core_thread.html#.Fiber "fibre" is basically a synonym of "coroutine".
Aug 29 2016
parent reply A D dev <addev dlang.com> writes:
On Monday, 29 August 2016 at 21:28:15 UTC, Cauterite wrote:
 Ranges serve some of the purposes that generators are often 
 used for: http://dlang.org/phobos/std_range.html

 But you can of course make true coroutine-based generators with 
 fibres: http://dlang.org/phobos/core_thread.html#.Fiber
Thanks. Both sound interesting. Will check.
Aug 29 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 08/29/2016 02:50 PM, A D dev wrote:
 On Monday, 29 August 2016 at 21:28:15 UTC, Cauterite wrote:
 Ranges serve some of the purposes that generators are often used for:
 http://dlang.org/phobos/std_range.html

 But you can of course make true coroutine-based generators with
 fibres: http://dlang.org/phobos/core_thread.html#.Fiber
Thanks. Both sound interesting. Will check.
Here is an example of a generator fiber: http://ddili.org/ders/d.en/fibers.html#ix_fibers.Generator,%20std.concurrency Ali
Aug 29 2016
parent A D dev <addev dlang.com> writes:
On Monday, 29 August 2016 at 22:03:35 UTC, Ali Çehreli wrote:
 Here is an example of a generator fiber:
Thanks, will take a look.
Aug 29 2016
prev sibling parent reply Meta <jared771 gmail.com> writes:
On Monday, 29 August 2016 at 21:24:52 UTC, A D dev wrote:
 Hi group,

 Does D have anything like the generators of Python and some 
 other languages?

 Thanks.
There's a Generator class in std.concurrency. I haven't used Python all that much so I can't say for certain whether it is the same or not. https://dlang.org/phobos/std_concurrency.html#.Generator
Aug 29 2016
parent A D dev <addev dlang.com> writes:
On Tuesday, 30 August 2016 at 00:57:05 UTC, Meta wrote:
 There's a Generator class in std.concurrency. I haven't used
 https://dlang.org/phobos/std_concurrency.html#.Generator
Thanks, Meta.
Aug 30 2016