Closed
Description
I'm not sure if this is an issue, but it sure seems to be. The following code:
fn main() {
let collatz = |i: int, acc: int| -> int {
if i == 1 { acc }
else if i % 2 == 0 { collatz(i/2, acc + 1) }
else { collatz(3*i + 1, acc + 1) }
};
println(fmt!("collatz(400) = %d", collatz(400, 0)));
}
Produces the following error on compilation:
> rustc collatz.rs
recurse.rs:4:23: 4:30 error: unresolved name: `collatz`.
recurse.rs:4 else if i % 2 == 0 { collatz(i/2, acc + 1) }
^~~~~~~
recurse.rs:5:9: 5:16 error: unresolved name: `collatz`.
recurse.rs:5 else { collatz(3*i + 1, acc + 1) }
^~~~~~~
error: aborting due to 2 previous errors
Why is the function not aware of its own name?
Metadata
Metadata
Assignees
Labels
No labels