News for hackers. Stuff that matters.
Re:Rust 1.47 by k__ on Thursday October 08, 2020 @10:16AM (#24719253)
What does "becoming const" mean?
Re:Rust 1.47 by mden on Thursday October 08, 2020 @10:25AM (#24719331)
Const values are inlined at compile time wherever they are used.

Const functions let you run code to define const values. This code will be run at compile time before the const values are inlined.

For example let's say you have a constant for PI but you need 2*PI. You could do the multiplication in const context, meaning the multiplication will happen during compilation and not execution. Slowly more and more of the language is becoming usable in const context so more advanced things can be done during compile time.

Re:Rust 1.47 by colejohnson66 on Thursday October 08, 2020 @10:58AM (#24719667)
Well, if you need `2*PI`, there’s now `f32::TAU` and `f64::TAU` :) You’re still correct though
Re:Rust 1.47 by happythomist on Thursday October 08, 2020 @10:21AM (#24719283)
I believe it's similar to "constexpr" in C++ -- it means those functions can now be evaluated at compile time.
Re:Rust 1.47 by dahfizz on Thursday October 08, 2020 @10:25AM (#24719326)
https://doc.rust-lang.org/reference/items/functions.html#con...

Basically, const functions can be used in places regular functions can't because they are directly "run" by the compiler at compile time.

Re:Rust 1.47 by hinkley on Thursday October 08, 2020 @01:57PM (#24721809)
I like that const functions occupy a space between a normal function and hygienic macros. You can avoid writing out lookup tables long-form where the entries are very predictable. For instance you could write a base64 encoder and decoder without putting ["a", "b", "c"... ] in your code base, and then have to worry if you accidentally put "D" in there twice. The typical alternative in other languages is to evaluate this at startup time, which adds latency to your program.

Compile-time function evaluation is also one of the features of the Jai programming language. If you can't get people to use your language, getting them to steal all your features is a good consolation prize.

Re:Rust 1.47 by jsheard on Thursday October 08, 2020 @07:10PM (#24724940)
> If you can't get people to use your language, getting them to steal all your features is a good consolation prize.

It's difficult to use Jai as long as it only exists on Jonathan Blows computer, he still hasn't released it

Re:Rust 1.47 by Ygg2 on Thursday October 08, 2020 @10:20AM (#24719280)
Means that functions are evaluated at compile time.

However in this case, these are const generics, so you no longer need to use macro to generate [char;1],[char;2]...

You just write [char; N] where N is const. Compiler determines which values of N are used and generates for them an appropriate version.

Re:Rust 1.47 by steveklabnik on Thursday October 08, 2020 @10:23AM (#24719313)
can be, you can call them at runtime too. And to be clear, const generics aren't stable yet, they're being used as an implementation detail of the standard library here, you cannot yet use them on stable in your code.
Re:Rust 1.47 by Nullabillity on Thursday October 08, 2020 @10:24AM (#24719318)
> However in this case, these are const generics, so you no longer need to use macro to generate [char;1],[char;2]...

Const generics still aren't stable. I believe the GP was talking about the list of new `const fn`s in the release (near the bottom of the post).