Skip to content

Instantly share code, notes, and snippets.

@ashleyh
Created March 22, 2012 21:52
Show Gist options
  • Save ashleyh/2164857 to your computer and use it in GitHub Desktop.
Save ashleyh/2164857 to your computer and use it in GitHub Desktop.
use std;
type counter = fn@ () -> int;
fn make_counter() -> counter {
let n = @mutable 0;
ret fn@ () -> int {
let r = *n;
*n += 1;
ret r;
};
}
fn main(_args:[str]) {
let c = make_counter();
std::io::println(#fmt("%d", c()));
std::io::println(#fmt("%d", c()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment