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

This is not an unique feature today, you can do the same in D and Rust and even C++14, I think.


"Hey Nim, 2014 called... they want their language features back."

I jest.

But seriously, D, Rust, and C++14 are about as familiar to me as Nim.


To be fair, D has had it since 2007 :)


Rust is planning to add that eventually, but in the meantime:

    fn foo(n: i32) -> i32 {
        n * 2
    }
    const y: i32 = foo(3);
error: function calls in constants are limited to struct and enum constructors [E0015]


You can do it with a compiler plugin; I suspect that's what the parent comment was referring to. Admittedly compiler plugins are pretty experimental at this time.


Sorry about that. I haven't tried this myself, I was told by a Rust user that its CTFE was on par with D's. I guess he was mistaken.


Not even close, sadly.


Or Common Lisp, 30 years ago.




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

Search: