Thread overview
[Issue 11880] New: Reserve the keyword "yield"
Jan 08, 2014
Jacob Carlborg
Jan 08, 2014
Vladimir Panteleev
Jan 08, 2014
Vladimir Panteleev
Jan 08, 2014
Maxim Fomin
Jan 11, 2014
Vladimir Panteleev
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880

           Summary: Reserve the keyword "yield"
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2014-01-07 18:38:02 PST ---
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; }}));
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880


Jacob Carlborg <doob@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob@me.com


--- Comment #1 from Jacob Carlborg <doob@me.com> 2014-01-07 23:35:19 PST ---
"yield" is already used for function names in core.Thread and core.Fiber.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880


Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com


--- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-01-08 09:42:11 EET ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880



--- Comment #3 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-01-08 09:42:54 EET ---
s/language construct/library construct/

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim@maxim-fomin.ru
         Resolution|                            |WONTFIX


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880



--- Comment #4 from bearophile_hugs@eml.cc 2014-01-08 03:06:11 PST ---
(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;
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 11, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11880



--- Comment #5 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-01-11 14:39:01 EET ---
(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/g7uhp6$317g$1@digitalmars.com

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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------