aboutsummaryrefslogtreecommitdiff
path: root/src/lambda.rs
blob: cf7b1ecdfe8e5af66b5fdb3104db6be973375bc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// I'm only a little sorry for this.

// Inline definition of anonymous functions. Examples:
// l!(42;)
// l!(i32 := 42)
// l!(i: i32 := i + 42)
// l!(i: i32, j: i32 -> i32 := i + j)
#[macro_export]
macro_rules! l {
    ($body: expr) => ({ fn f() { $body } f });
    ($res: ty := $body: expr) => ({ fn f() -> $res { $body } f });
    ($($n: ident: $t: ty),+ := $body: expr) => ({
        fn f($($n: $t),+) { $body } f
    });
    ($($n: ident: $t: ty),+ -> $res: ty := $body: expr) => ({
        fn f($($n: $t),+) -> $res { $body } f
    })
}