digitalmars.D.bugs - [Issue 16272] New: Yield like semantics for function execution
- via Digitalmars-d-bugs (52/52) Jul 12 2016 https://issues.dlang.org/show_bug.cgi?id=16272
https://issues.dlang.org/show_bug.cgi?id=16272 Issue ID: 16272 Summary: Yield like semantics for function execution Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: TeddyBear12311 gmail.com In some cases it would be nice to break the execution flow of a function and re-continue at a later time. This reduces bloat and complexity. int A(int i) { ... ?yield; ... ?yield; ... ?yield; ... return 0; } void B() { int x = 3; auto uuid = yield A(ref x) // Calls A but activates ?yields //returns from A after first ?yield ... x = 6; continue!uuid(A(ref x)) // continues // returns from A after second ?yield ... continue!uuid(A(ref x)); // returns from A after third ?yield ... break!uud(A()); // breaks out of A as it A executed a return statement. No return value is given. } All inputs to A are by ref when yielding so they can be modified. The break is optional but allows one to terminate execution of the function. Every continue must match a ?yield up to a break. uuid's are simply ways to identify different function execution strains. Does this allow for total chaos if used wrong? Yes! It's more valuable to create simple and complex state machines very effectively with minimal work and better understanding of the complexity. Each ?yield statement can be seen as a pause in the state machine between transitions. --
Jul 12 2016