Skip to content

Instantly share code, notes, and snippets.

@jaen
Created April 7, 2013 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaen/5331133 to your computer and use it in GitHub Desktop.
Save jaen/5331133 to your computer and use it in GitHub Desktop.
rustc weirdness
fn sum(a: int, b: int) -> int { a + b }
fn main() {
let a = |x:int| { |y:int| -> int { x + y } };
let b = a(2);
io::println(int::to_str(sum(2, 3)));
io::println(int::to_str(a(2)(3)));
io::println(int::to_str(b(3)));
}
// Which when run outputs
> 5
> 6
> 39739523 // random value
// meanwhile in the REPL
[jaen@yuuki ~]$ rust sketch
WARNING: The Rust REPL is experimental and may be
unstable. If you encounter problems, please use the
compiler instead.
rusti> fn sum(a: int, b: int) -> int { a + b }
()
rusti> let a = |x:int| { |y:int| -> int { x + y } };
<anon>:36:4: 36:7 warning: unused variable: `a`
<anon>:36 let a = |x:int| { |y:int| -> int { x + y } };
^~~
()
rusti> let b = a(2);
<anon>:38:4: 38:7 warning: unused variable: `b`
<anon>:38 let b = a(2);
^~~
()
rusti> sum(2, 3)
<anon>:37:4: 37:7 warning: unused variable: `b`
<anon>:37 let b = a(2);
^~~
5
rusti> a(2)(3)
<anon>:37:4: 37:7 warning: unused variable: `b`
<anon>:37 let b = a(2);
^~~
5
rusti> b(3)
5
rusti>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment