Bug 11880 – Reserve the keyword "yield"

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-07T18:38:00Z
Last change time
2014-12-03T21:58:37Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-01-07T18:38:02Z
I suggest to reserve the keyword "yield" for future usage (just like the keyword "macro", "cent", "ucent"). This will avoid backward compatibility problems with D code that uses variable names "yield" today. See Issue 5660 for info on "yield". Today code that uses "yield" should give an explicit error message like this: test.d(2): Error: yield not implemented And this should compile: void main() { static assert(!__traits(compiles, { yield(int) foo() { yield 1; }})); }
Comment #1 by doob — 2014-01-07T23:35:19Z
"yield" is already used for function names in core.Thread and core.Fiber.
Comment #2 by dlang-bugzilla — 2014-01-07T23:42:11Z
As I understand, "yield" doesn't need to be a keyword - it can be implemented as a language construct. The only limitation is that coroutines need to be started explicitly (which I think this is a plus as it improves readability). I suggest closing this as WONTFIX.
Comment #3 by dlang-bugzilla — 2014-01-07T23:42:54Z
s/language construct/library construct/
Comment #4 by bearophile_hugs — 2014-01-08T03:06:11Z
(In reply to comment #2) > As I understand, "yield" doesn't need to be a keyword - it can be implemented > as a language construct. Do you have an example usage syntax (and implementation)? And is it going in Phobos? What about Issue 5660 ? > The only limitation is that coroutines need to be > started explicitly (which I think this is a plus as it improves readability). This is the syntax I suggested, I think it's readable. What's the more readable usage syntax that you suggest? yield(int) foo() { yield 1; yield 2; } void main() { import std.stdio, std.algorithm; foo.map!(x => x).writeln; }
Comment #5 by dlang-bugzilla — 2014-01-11T04:39:01Z
(In reply to comment #4) > Do you have an example usage syntax (and implementation)? You posted this 5 years ago: http://forum.dlang.org/post/[email protected] There are other, similar implementations. > And is it going in Phobos? I don't know of any plans for that. > What about Issue 5660 ? The same arguments apply there too. I see people posted their own coroutine implementations there as well. > This is the syntax I suggested, I think it's readable. What's the more readable > usage syntax that you suggest? My argument is that the cost of introducing a breaking change in the language is not justified for the sake of syntax sugar.
Comment #6 by bearophile_hugs — 2014-12-03T21:58:37Z
(In reply to Vladimir Panteleev from comment #2) > As I understand, "yield" doesn't need to be a keyword - it can be > implemented as a language construct. The only limitation is that coroutines > need to be started explicitly (which I think this is a plus as it improves > readability). > > I suggest closing this as WONTFIX. Currently std.concurreny.Generator has a not nice usage syntax, it is not @nogc, not pure, not nothrow, and not safe, and it allocates too much memory, so it's kind of useless in the functional-style code where it's more useful, and for recursive generators.