What is the difference between enum and shared immutable?
Ali Çehreli
acehreli at yahoo.com
Thu Oct 29 16:45:51 UTC 2020
On 10/28/20 3:07 PM, H. S. Teoh wrote:
> A shared immutable is initialized at compile-time,
To prevent a misunderstanding, immutable can be initialized at run time
as well. On the other hand, immutable initialized at compile time was
surprising to me when I learned it recently:
import std;
immutable string p;
shared static this() {
p = environment["PATH"]; // <-- Run time
}
// Ali learned this relatively recently
// (immutable at compile time):
immutable lines = import("myfile.txt").splitter('\n').array;
pragma(msg, lines);
void main() {
}
Ali
More information about the Digitalmars-d-learn
mailing list