On Mon, Apr 29, 2013 at 9:30 PM, Erik S <sw...@earthling.net> wrote:
> On 4/29/2013 2:00 PM, Graydon Hoare wrote:
>> Yes. Formalizing and completing the definition of the constant
>> expression subgrammar would be extremely valuable. It's one of the
>> major high-risk areas remaining the the design space. -Graydon
> VHDL is a very different language from Rust (it's a hardware design
> language, not a normal programming language), but it has the nicest
> constant system I've worked with.
>
> The rule is basically that constant expressions can contain:
>
> Literals (i.e. 5, 0x20)
> Expressions that depend on constants  (i.e. 0x5 + 10 * const_k)
> Any "pure" function whose arguments are constant.   (i.e. 5 + f_pure(5,
> const_k) )
>
> It's this last rule that is truly beautiful. You can use the same
> functions in both constant initialization and run-time code, with only
> the requirement that they are pure. Pure functions are ones whose output
> depends only on their arguments (and constants). Allowing functions to
> initialize constants avoids the whole annoyance in C/C++ where you have
> to use macros to make things compile-time const. It also allows a
> surprising amount of compile-time optimization.
>
> I don't know how realistic this is for constants in a language like rust
> - but it would be very elegant if it could work.
>

We used to have a notion of pure functions in Rust, but that was
removed recently. It originally existed for typestate (a feature we
removed a while ago) and more recently to assist the borrow checker.
We removed it because in Rust, it was impractical to define an
easily-checkable pure subset of the language. Bringing it back in is
somewhat less likely than adding significant whitespace.

Cheers,
Tim



-- 
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
"Too much to carry, too much to let go
Time goes fast, learning goes slow." -- Bruce Cockburn
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to