Created
December 7, 2017 16:04
-
-
Save anonymous/fe0ce1b36e49f8ddde2da21cfa3777a6 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! siaf { | |
(|$($parm:ident),* $(,)*| $body:expr) => {{ | |
/* ensure no captures */ let closure: fn($($parm: _),*)->_ = |$($parm),*| $body; | |
(closure)($($parm),*) | |
}} | |
} | |
fn compute_g(a: i32, b: i32, c: i32) -> i32 { | |
let d = siaf!(|a, b| a + c); | |
let (e, f) = siaf!(|d| (d - 1, d + 1)); | |
let g = siaf!(|c, e, f| c + e + f ); | |
g | |
} | |
fn main() { | |
println!("{}", compute_g(1, 2, 3)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment