public
Created

  • Download Gist
astrieanna1.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn outer1(i: &mut int) {
if *i < 9 {
*i += 1;
outer2(i);
}
}
 
fn outer2(i: &mut int) {
*i += 1;
outer1(i);
}
 
fn main() {
let mut foo = 0;
outer1(&mut foo);
io::println(fmt!("%d", foo)); // prints "10"
}
astrieanna2.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
fn outer1(i: &mut int) {
if *i < 9 {
*i += 1;
outer2(i);
}
}
 
fn outer2(i: &mut int) {
*i += 1;
outer1(i);
}
 
let mut foo = 0;
outer1(&mut foo);
io::println(fmt!("%d", foo)); // prints "10"
}
astrieanna3.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
let bar = 1;
 
fn outer1(i: &mut int) {
if *i < 9 {
*i += bar; // error: attempted dynamic environment-capture
outer2(i);
}
}
 
fn outer2(i: &mut int) {
*i += bar; // error: attempted dynamic environment-capture
outer1(i);
}
 
let mut foo = 0;
outer1(&mut foo);
io::println(fmt!("%d", foo));
}
astrieanna4.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
let bar = 1;
 
let outer1 = |i| {
if *i < 9 {
*i += bar;
outer2(i); // error: unresolved name: outer2
}
};
 
let outer2 = |i| {
*i += bar;
outer1(i);
};
 
let mut foo = 0;
io::println(fmt!("%d", foo));
outer1(&mut foo);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.