Skip to content

Instantly share code, notes, and snippets.

@durka
Forked from anonymous/playground.rs
Created December 7, 2017 16:04
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 durka/9a80307f52a7c23825d28178c37db5a5 to your computer and use it in GitHub Desktop.
Save durka/9a80307f52a7c23825d28178c37db5a5 to your computer and use it in GitHub Desktop.
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