Would be correct to say that literals in Julia are “immutable values known at compile times” ?
IMO, the statement is correct, but not precise.
struct MyStruct
x
end
const m = MyStruct(5)
Here, m
holds an immutable value known at compile time as well. But this value isn’t a literal. (please correct me if I’m wrong)
Depends on what do you call literal and what do you want to get from this statement…
If you are only talking about strings and builtin numbers, sure, but that’s nothing more than saying strings and builtin numbers are immutable types (actually that’s already questionable for BigInt
and BigFloat
). It has nothing to do with “literal”.
We also have string macros that are basically user-defined literals in C++. They can construct either mutable or immutable objects and they may or may not be known at compile time.
If you define only those that are immutable and known at compile time as literals, then yes, but that’s just the definition and doesn’t really carry much more meaning.