Comments (8)
Discussed in the rust-lang meeting.
There is some amount of excitement and enthusiasm for taking this approach eventually, however we feel like we don't presently have the design bandwidth to oversee a project of this kind, so we're going to put this into final comment period with disposition close.
We do expect at some point in the future to be talking about the ability to have built-in syntax for iterators or streams, and it would make sense to revisit this discussion at that time.
To that end, one thing that would really be appreciated is if someone wanted to try and capture the state of the design discussion here, including unknowns and challenges. We could put it under the lang-team.rust-lang.org website "design notes" section.
from lang-team.
Sounds good! Thanks for hearing me out.
one thing that would really be appreciated is if someone wanted to try and capture the state of the design discussion here
I'll go ahead and put something comprehensive together in the next week when I have some free time.
from lang-team.
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
from lang-team.
I have a concern that changing the closure argument variables after each yield
is very unintuitive (action at a distance) and resume arguments should instead be retrieved from the yield
expression like so:
let my_generator = |arg1: i64| {
// can get initial resume arg by instead starting
// with something like (syntax up for bikeshedding):
// |arg1: i64| initial_resume: &'static str = yield {
//
dbg!(&arg1);
let yielded1 = 123;
// key part of concern:
// yields yielded1 to caller, gets resume_arg back,
// does *NOT* modify arg1 since arg1 wasn't mentioned
let resume_arg: &'static str = yield yielded1;
dbg!(&arg1); // always prints same thing as previous dbg!
123.45f64
};
// exact generator type up for debate
let _: Fn(i64) -> (FnPin(&'static str) -> YieldOrReturn<i32, f64>) = my_generator;
from lang-team.
@programmerjake I get it. I was in the yield-expression camp for a long time too. But trust me, assign-on-yield really is the better option! I'll list a few reasons here but if anyone is unconvinced, they should drop by Zulip and duke it out with me there.
-
yield
is more likereturn
than like anything else. In fact, under this proposal the only difference between the two is where the closure resumes: after the statement or at the beginning.return
reassigns arguments soyield
does too. -
No action at a distance! People are afraid of the "magic mutation" but Rust as a language is really good at dealing with unexpected mutation. Imagine some code:
|items| {
for _ in items {
yield;
}
}
This will error out with something like:
error[E0506]: cannot pass new `items` because it is borrowed
--> src/lib.rs:3:9
|
2 | for _ in &items {
| ------
| |
| borrow of `items` occurs here
| borrow later used here
3 | yield;
| ^^^^^ assignment to borrowed `items` occurs here
|
= help: consider moving `items` into a new binding before borrowing
So even if a user totally misunderstands the behavior of yield
, their data still can't change out from under them.
- Assign-on-yield handles the common case far better and is almost always more ergonomic. In my prototyping, it is rare that I want to save a resume argument from reassignment and use it later. Take a look at my examples above! In all of them there are only two places where I choose not to discard the previous resume argument:
let mut min_health = my_health;
andlet most = c.to_digit(16);
. And even in those places, a yield expression gets in the way more than anything else.let most = (yield None).to_digit(16)
isn't great but the only way I can get the AI example to work at all is by pointlessly re-inventing assign-on-yield:
|mut is_opponent_near, mut my_health| loop {
// Find opponent
while !is_opponent_near {
let state = yield Wander;
is_opponent_near = state.0;
my_health = state.1;
}
// Do battle!
let mut min_health = my_health;
...
from lang-team.
Placing in final comment period and we'll revisit next triage meeting.
from lang-team.
#52 is up.
from lang-team.
Closing this issue. People should review #52 asynchronously, and we can talk about it for a future roadmap item.
from lang-team.
Related Issues (20)
- Nail down cargo-script syntax proposal HOT 2
- T-types proposal for stabilizing type alias impl Trait (TAIT)
- 2024 Edition Review HOT 1
- Design meeting: resolve ABI issues around target-feature HOT 6
- Website broken HOT 5
- Design meeting: Rust for Linux
- Design meeting: Match ergonomics 2024
- Lang-team RFC guidelines appear to be out of date
- Design meeting: Profiles
- Bounds for RPIT/RPITIT/async fn
- Discuss RFC 2442: Simple postfix macros HOT 3
- Discuss Rust 2024 edition planning: 2024-01-10
- Discuss ideas for GSoC 2024 HOT 2
- Discuss feedback for T-spec sample chapters HOT 1
- Lang discussion: Item-level `const {}` blocks, and `const { assert!(...) }` HOT 1
- Discuss temporary lifetimes 2024 RFC HOT 1
- Discuss arbitrary self types v2 RFC
- Proposal: Remove `i128`/`u128` from the `improper_ctypes` lint HOT 7
- Discuss the never type situation
- Extended triage meeting 2024-03-20 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lang-team.