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.
This is already possible using a library solution, see https://dlang.org/phobos/std_concurrency.html#.Generator
(In reply to Mathias Lang from comment #1) > This is already possible using a library solution, see > https://dlang.org/phobos/std_concurrency.html#.Generator I believe their is a subtle difference. I could be mistaken because I don't know the depth of fibers. Fibers are more concurrency related and imitate a task switch. In this case with functions, no task switching like behavior is needed. Just a push and pop of the locals and a few other little things. It may be exactly what a fiber does though? I'm thinking it is more like thread(heavy) > fiber(medium) > functional yield(light weight).
This would require a DIP, however I doubt that it is going to pass through. As pointed out, fibers do this exactly. I am going to close this. If you want to pursue it TeddyBear12311@gmail.com, please submit a DIP.