Enforced immutability: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added one-off type checks, syntax colouring, marked p2js compatible)
m (Regularize header markup to recommended on category page)
Line 153: Line 153:
It is possible to remove the <tt>const</tt> qualifier of the type a pointer points to through a cast, but doing so will result in undefined behavior.
It is possible to remove the <tt>const</tt> qualifier of the type a pointer points to through a cast, but doing so will result in undefined behavior.


=={{header|C sharp}}==
=={{header|C sharp|C#}}==
Fields can be made read-only (a runtime constant) with the '''readonly''' keyword.
Fields can be made read-only (a runtime constant) with the '''readonly''' keyword.
<lang csharp>readonly DateTime now = DateTime.Now;</lang>
<lang csharp>readonly DateTime now = DateTime.Now;</lang>
Line 406: Line 406:
constant str = "immutable string"</lang>
constant str = "immutable string"</lang>


=={{header|F#}}==
=={{header|F Sharp|F#}}==
As a functional language, everything in F# is immutable by default. Interestingly, <code>const</code> is a reserved word but is non-functional.
As a functional language, everything in F# is immutable by default. Interestingly, <code>const</code> is a reserved word but is non-functional.
<lang fsharp>let hello = "Hello!"</lang>
<lang fsharp>let hello = "Hello!"</lang>