Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is an interesting claim about Rust:

> However, it prevents you from writing generic macros that use any l-value – we can’t write swap!(x[0], x[1]) as we could in Common Lisp.

As long as `macro_rules!` has existed (I could be wrong about before 0.8 though), you can wrote a macro that takes any expression, and will error from the assignment when the expression is not an lvalue:

    macro_rules! swap {
        ($x:expr, $y:expr) => ({
            let tmp = $x;
            $x = $y;
            $y = tmp;
        })
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: