<s>
In	O
object-oriented	B-Language
and	O
functional	B-Language
programming	I-Language
,	O
an	O
immutable	B-Application
object	I-Application
(	O
unchangeable	O
object	O
)	O
is	O
an	O
object	O
whose	O
state	O
cannot	O
be	O
modified	O
after	O
it	O
is	O
created	O
.	O
</s>
<s>
This	O
is	O
in	O
contrast	O
to	O
a	O
mutable	B-Application
object	I-Application
(	O
changeable	O
object	O
)	O
,	O
which	O
can	O
be	O
modified	O
after	O
it	O
is	O
created	O
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
an	O
object	O
is	O
considered	O
immutable	B-Application
even	O
if	O
some	O
internally	O
used	O
attributes	O
change	O
,	O
but	O
the	O
object	O
's	O
state	O
appears	O
unchanging	O
from	O
an	O
external	O
point	O
of	O
view	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
object	O
that	O
uses	O
memoization	O
to	O
cache	O
the	O
results	O
of	O
expensive	O
computations	O
could	O
still	O
be	O
considered	O
an	O
immutable	B-Application
object	I-Application
.	O
</s>
<s>
Strings	O
and	O
other	O
concrete	O
objects	O
are	O
typically	O
expressed	O
as	O
immutable	B-Application
objects	I-Application
to	O
improve	O
readability	O
and	O
runtime	O
efficiency	O
in	O
object-oriented	B-Language
programming	I-Language
.	O
</s>
<s>
Immutable	B-Application
objects	I-Application
are	O
also	O
useful	O
because	O
they	O
are	O
inherently	O
thread-safe	B-Operating_System
.	O
</s>
<s>
Other	O
benefits	O
are	O
that	O
they	O
are	O
simpler	O
to	O
understand	O
and	O
reason	O
about	O
and	O
offer	O
higher	O
security	O
than	O
mutable	B-Application
objects	I-Application
.	O
</s>
<s>
In	O
imperative	B-Application
programming	I-Application
,	O
values	O
held	O
in	O
program	O
variables	O
whose	O
content	O
never	O
changes	O
are	O
known	O
as	O
constants	O
to	O
differentiate	O
them	O
from	O
variables	O
that	O
could	O
be	O
altered	O
during	O
execution	O
.	O
</s>
<s>
Sometimes	O
,	O
one	O
talks	O
of	O
certain	O
fields	O
of	O
an	O
object	O
being	O
immutable	B-Application
.	O
</s>
<s>
This	O
means	O
that	O
there	O
is	O
no	O
way	O
to	O
change	O
those	O
parts	O
of	O
the	O
object	O
state	O
,	O
even	O
though	O
other	O
parts	O
of	O
the	O
object	O
may	O
be	O
changeable	O
(	O
weakly	O
immutable	B-Application
)	O
.	O
</s>
<s>
If	O
all	O
fields	O
are	O
immutable	B-Application
,	O
then	O
the	O
object	O
is	O
immutable	B-Application
.	O
</s>
<s>
If	O
the	O
whole	O
object	O
cannot	O
be	O
extended	O
by	O
another	O
class	O
,	O
the	O
object	O
is	O
called	O
strongly	O
immutable	B-Application
.	O
</s>
<s>
const	O
in	O
C++	B-Language
,	O
final	O
in	O
Java	B-Language
)	O
that	O
designates	O
the	O
field	O
as	O
immutable	B-Application
.	O
</s>
<s>
Some	O
languages	O
reverse	O
it	O
:	O
in	O
OCaml	B-Language
,	O
fields	O
of	O
an	O
object	O
or	O
record	O
are	O
by	O
default	O
immutable	B-Application
,	O
and	O
must	O
be	O
explicitly	O
marked	O
with	O
mutable	B-Application
to	O
be	O
so	O
.	O
</s>
<s>
In	O
most	O
object-oriented	B-Language
languages	I-Language
,	O
objects	O
can	O
be	O
referred	O
to	O
using	O
references	O
.	O
</s>
<s>
Some	O
examples	O
of	O
such	O
languages	O
are	O
Java	B-Language
,	O
C++	B-Language
,	O
C#	B-Application
,	O
VB.NET	B-Language
,	O
and	O
many	O
scripting	B-Language
languages	I-Language
,	O
such	O
as	O
Perl	B-Language
,	O
Python	B-Language
,	O
and	O
Ruby	B-Language
.	O
</s>
<s>
If	O
an	O
object	O
is	O
known	O
to	O
be	O
immutable	B-Application
,	O
it	O
is	O
preferred	O
to	O
create	O
a	O
reference	O
of	O
it	O
instead	O
of	O
copying	O
the	O
entire	O
object	O
.	O
</s>
<s>
This	O
is	O
done	O
to	O
conserve	O
memory	B-General_Concept
by	O
preventing	O
data	O
duplication	O
and	O
avoid	O
calls	O
to	O
constructors	O
and	O
destructors	O
;	O
it	O
also	O
results	O
in	O
a	O
potential	O
boost	O
in	O
execution	O
speed	O
.	O
</s>
<s>
The	O
reference	O
copying	O
technique	O
is	O
much	O
more	O
difficult	O
to	O
use	O
for	O
mutable	B-Application
objects	I-Application
,	O
because	O
if	O
any	O
user	O
of	O
a	O
mutable	B-Application
object	I-Application
reference	O
changes	O
it	O
,	O
all	O
other	O
users	O
of	O
that	O
reference	O
see	O
the	O
change	O
.	O
</s>
<s>
The	O
observer	B-Language
pattern	I-Language
is	O
an	O
alternative	O
technique	O
for	O
handling	O
changes	O
to	O
mutable	B-Application
objects	I-Application
.	O
</s>
<s>
A	O
technique	O
that	O
blends	O
the	O
advantages	O
of	O
mutable	B-Application
and	O
immutable	B-Application
objects	I-Application
,	O
and	O
is	O
supported	O
directly	O
in	O
almost	O
all	O
modern	O
hardware	O
,	O
is	O
copy-on-write	B-Language
(	O
COW	O
)	O
.	O
</s>
<s>
Therefore	O
,	O
under	O
COW	O
,	O
all	O
users	O
appear	O
to	O
have	O
a	O
mutable	B-Application
version	O
of	O
their	O
objects	O
,	O
although	O
in	O
the	O
case	O
that	O
users	O
do	O
not	O
modify	O
their	O
objects	O
,	O
the	O
space-saving	O
and	O
speed	O
advantages	O
of	O
immutable	B-Application
objects	I-Application
are	O
preserved	O
.	O
</s>
<s>
Copy-on-write	B-Language
is	O
popular	O
in	O
virtual	B-Architecture
memory	I-Architecture
systems	O
because	O
it	O
allows	O
them	O
to	O
save	O
memory	B-General_Concept
space	O
while	O
still	O
correctly	O
handling	O
anything	O
an	O
application	O
program	O
might	O
do	O
.	O
</s>
<s>
Some	O
languages	O
do	O
this	O
automatically	O
:	O
for	O
example	O
,	O
Python	B-Language
automatically	O
interns	O
short	O
strings	O
.	O
</s>
<s>
(	O
Even	O
if	O
the	O
algorithm	O
is	O
not	O
guaranteed	O
to	O
be	O
comprehensive	O
,	O
there	O
still	O
exists	O
the	O
possibility	O
of	O
a	O
fast	B-General_Concept
path	I-General_Concept
case	O
improvement	O
when	O
the	O
objects	O
are	O
equal	O
and	O
use	O
the	O
same	O
reference	O
.	O
)	O
</s>
<s>
Interning	O
is	O
generally	O
only	O
useful	O
for	O
immutable	B-Application
objects	I-Application
.	O
</s>
<s>
Immutable	B-Application
objects	I-Application
can	O
be	O
useful	O
in	O
multi-threaded	O
applications	O
.	O
</s>
<s>
Multiple	O
threads	O
can	O
act	O
on	O
data	O
represented	O
by	O
immutable	B-Application
objects	I-Application
without	O
concern	O
of	O
the	O
data	O
being	O
changed	O
by	O
other	O
threads	O
.	O
</s>
<s>
Immutable	B-Application
objects	I-Application
are	O
therefore	O
considered	O
more	O
thread-safe	B-Operating_System
than	O
mutable	B-Application
objects	I-Application
.	O
</s>
<s>
Immutability	B-Application
does	O
not	O
imply	O
that	O
the	O
object	O
as	O
stored	O
in	O
the	O
computer	O
's	O
memory	B-General_Concept
is	O
unwriteable	O
.	O
</s>
<s>
Rather	O
,	O
immutability	B-Application
is	O
a	O
compile-time	B-Application
construct	O
that	O
indicates	O
what	O
a	O
programmer	O
can	O
do	O
through	O
the	O
normal	O
interface	O
of	O
the	O
object	O
,	O
not	O
necessarily	O
what	O
they	O
can	O
absolutely	O
do	O
(	O
for	O
instance	O
,	O
by	O
circumventing	O
the	O
type	O
system	O
or	O
violating	O
const	O
correctness	O
in	O
C	B-Language
or	O
C++	B-Language
)	O
.	O
</s>
<s>
In	O
Python	B-Language
,	O
Java	B-Language
and	O
the	O
.NET	B-Application
Framework	I-Application
,	O
strings	O
are	O
immutable	B-Application
objects	I-Application
.	O
</s>
<s>
Both	O
Java	B-Language
and	O
the	O
.NET	B-Application
Framework	I-Application
have	O
mutable	B-Application
versions	O
of	O
string	O
.	O
</s>
<s>
In	O
Java	B-Language
these	O
are	O
StringBuffer	O
and	O
StringBuilder	O
(	O
mutable	B-Application
versions	O
of	O
Java	B-Language
)	O
and	O
in	O
.NET	B-Application
this	O
is	O
StringBuilder	O
(	O
mutable	B-Application
version	O
of	O
.Net	B-Application
String	O
)	O
.	O
</s>
<s>
Python	B-Language
3	O
has	O
a	O
mutable	B-Application
string	O
(	O
bytes	O
)	O
variant	O
,	O
named	O
bytearray	O
.	O
</s>
<s>
Additionally	O
,	O
all	O
of	O
the	O
primitive	B-Language
wrapper	I-Language
classes	O
in	O
Java	B-Language
are	O
immutable	B-Application
.	O
</s>
<s>
Similar	O
patterns	O
are	O
the	O
Immutable	B-Application
Interface	I-Application
and	O
Immutable	B-Application
Wrapper	O
.	O
</s>
<s>
In	O
pure	O
functional	B-Language
programming	I-Language
languages	I-Language
it	O
is	O
not	O
possible	O
to	O
create	O
mutable	B-Application
objects	I-Application
without	O
extending	O
the	O
language	O
(	O
e.g.	O
</s>
<s>
via	O
a	O
mutable	B-Application
references	O
library	O
or	O
a	O
foreign	B-Application
function	I-Application
interface	I-Application
)	O
,	O
so	O
all	O
objects	O
are	O
immutable	B-Application
.	O
</s>
<s>
In	O
Ada	B-Language
,	O
any	O
object	O
is	O
declared	O
either	O
variable	O
(	O
i.e.	O
</s>
<s>
mutable	B-Application
;	O
typically	O
the	O
implicit	O
default	O
)	O
,	O
or	O
constant	O
(	O
i.e.	O
</s>
<s>
immutable	B-Application
)	O
via	O
the	O
constant	O
keyword	O
.	O
</s>
<s>
Subprogram	O
parameters	O
are	O
immutable	B-Application
in	O
the	O
in	O
mode	O
,	O
and	O
mutable	B-Application
in	O
the	O
in	O
out	O
and	O
out	O
modes	O
.	O
</s>
<s>
In	O
C#	B-Application
you	O
can	O
enforce	O
immutability	B-Application
of	O
the	O
fields	O
of	O
a	O
class	O
with	O
the	O
readonly	O
statement	O
.	O
</s>
<s>
By	O
enforcing	O
all	O
the	O
fields	O
as	O
immutable	B-Application
,	O
you	O
obtain	O
an	O
immutable	B-Application
type	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
a	O
const-correct	O
implementation	O
of	O
Cart	O
would	O
allow	O
the	O
user	O
to	O
create	O
instances	O
of	O
the	O
class	O
and	O
then	O
use	O
them	O
as	O
either	O
const	O
(	O
immutable	B-Application
)	O
or	O
mutable	B-Application
,	O
as	O
desired	O
,	O
by	O
providing	O
two	O
different	O
versions	O
of	O
the	O
items( )	O
method	O
.	O
</s>
<s>
(	O
Notice	O
that	O
in	O
C++	B-Language
it	O
is	O
not	O
necessary	O
—	O
and	O
in	O
fact	O
impossible	O
—	O
to	O
provide	O
a	O
specialized	O
constructor	O
for	O
const	O
instances	O
.	O
)	O
</s>
<s>
C++	B-Language
also	O
provides	O
abstract	O
(	O
as	O
opposed	O
to	O
bitwise	O
)	O
immutability	B-Application
via	O
the	O
mutable	B-Application
keyword	O
,	O
which	O
lets	O
a	O
member	B-Application
variable	I-Application
be	O
changed	O
from	O
within	O
a	O
const	O
method	O
.	O
</s>
<s>
In	O
D	B-Application
,	O
there	O
exist	O
two	O
type	B-Language
qualifiers	I-Language
,	O
const	O
and	O
immutable	B-Application
,	O
for	O
variables	O
that	O
cannot	O
be	O
changed	O
.	O
</s>
<s>
Unlike	O
C++'s	O
const	O
,	O
Java	B-Language
's	O
final	O
,	O
and	O
C#'s	O
readonly	O
,	O
they	O
are	O
transitive	O
and	O
recursively	O
apply	O
to	O
anything	O
reachable	O
through	O
references	O
of	O
such	O
a	O
variable	O
.	O
</s>
<s>
The	O
difference	O
between	O
const	O
and	O
immutable	B-Application
is	O
what	O
they	O
apply	O
to	O
:	O
const	O
is	O
a	O
property	O
of	O
the	O
variable	O
:	O
there	O
might	O
legally	O
exist	O
mutable	B-Application
references	O
to	O
referred	O
value	O
,	O
i.e.	O
</s>
<s>
In	O
contrast	O
,	O
immutable	B-Application
is	O
a	O
property	O
of	O
the	O
referred	O
value	O
:	O
the	O
value	O
and	O
anything	O
transitively	O
reachable	O
from	O
it	O
cannot	O
change	O
(	O
without	O
breaking	O
the	O
type	O
system	O
,	O
leading	O
to	O
undefined	B-Language
behavior	I-Language
)	O
.	O
</s>
<s>
Any	O
reference	O
of	O
that	O
value	O
must	O
be	O
marked	O
const	O
or	O
immutable	B-Application
.	O
</s>
<s>
Basically	O
for	O
any	O
unqualified	O
type	O
T	O
,	O
const(T )	O
is	O
the	O
disjoint	O
union	O
of	O
T	O
(	O
mutable	B-Application
)	O
and	O
immutable(T )	O
.	O
</s>
<s>
For	O
a	O
mutable	B-Application
C	B-Language
object	O
,	O
its	O
mField	O
can	O
be	O
written	O
to	O
.	O
</s>
<s>
For	O
a	O
const(C )	O
object	O
,	O
mField	O
cannot	O
be	O
modified	O
,	O
it	O
inherits	O
const	O
;	O
iField	O
is	O
still	O
immutable	B-Application
as	O
it	O
is	O
the	O
stronger	O
guarantee	O
.	O
</s>
<s>
For	O
an	O
immutable(C )	O
,	O
all	O
fields	O
are	O
immutable	B-Application
.	O
</s>
<s>
Inside	O
the	O
braces	O
,	O
c	B-Language
might	O
refer	O
to	O
the	O
same	O
object	O
as	O
m	O
,	O
so	O
mutations	O
to	O
m	O
could	O
indirectly	O
change	O
c	B-Language
as	O
well	O
.	O
</s>
<s>
c	B-Language
might	O
refer	O
to	O
the	O
same	O
object	O
as	O
i	O
,	O
but	O
since	O
the	O
value	O
then	O
is	O
immutable	B-Application
,	O
there	O
are	O
no	O
changes	O
.	O
</s>
<s>
immutable	B-Application
is	O
a	O
bidirectional	O
guarantee	O
(	O
the	O
function	O
will	O
not	O
change	O
the	O
value	O
and	O
the	O
caller	O
must	O
not	O
change	O
it	O
)	O
.	O
</s>
<s>
Values	O
that	O
are	O
const	O
or	O
immutable	B-Application
must	O
be	O
initialized	O
by	O
direct	O
assignment	O
at	O
the	O
point	O
of	O
declaration	O
or	O
by	O
a	O
constructor	O
.	O
</s>
<s>
Because	O
const	O
parameters	O
forget	O
if	O
the	O
value	O
was	O
mutable	B-Application
or	O
not	O
,	O
a	O
similar	O
construct	O
,	O
inout	O
,	O
acts	O
,	O
in	O
a	O
sense	O
,	O
as	O
a	O
variable	O
for	O
mutability	O
information	O
.	O
</s>
<s>
A	O
function	O
of	O
type	O
const(S )	O
function(const(T )	O
)	O
returns	O
const(S )	O
typed	O
values	O
for	O
mutable	B-Application
,	O
const	O
and	O
immutable	B-Application
arguments	O
.	O
</s>
<s>
In	O
contrast	O
,	O
a	O
function	O
of	O
type	O
inout(S )	O
function(inout(T )	O
)	O
returns	O
S	O
for	O
mutable	B-Application
T	O
arguments	O
,	O
const(S )	O
for	O
const(T )	O
values	O
,	O
and	O
immutable(S )	O
for	O
immutable(T )	O
values	O
.	O
</s>
<s>
Casting	O
immutable	B-Application
values	I-Application
to	O
mutable	B-Application
inflicts	O
undefined	B-Language
behavior	I-Language
upon	O
change	O
,	O
even	O
if	O
the	O
original	O
value	O
comes	O
from	O
a	O
mutable	B-Application
origin	O
.	O
</s>
<s>
Casting	O
mutable	B-Application
values	O
to	O
immutable	B-Application
can	O
be	O
legal	O
when	O
there	O
remain	O
no	O
mutable	B-Application
references	O
afterward	O
.	O
</s>
<s>
"	O
An	O
expression	O
may	O
be	O
converted	O
from	O
mutable	B-Application
(	O
...	O
)	O
to	O
immutable	B-Application
if	O
the	O
expression	O
is	O
unique	O
and	O
all	O
expressions	O
it	O
transitively	O
refers	O
to	O
are	O
either	O
unique	O
or	O
immutable.	O
"	O
</s>
<s>
If	O
the	O
compiler	O
cannot	O
prove	O
uniqueness	O
,	O
the	O
casting	O
can	O
be	O
done	O
explicitly	O
and	O
it	O
is	O
up	O
to	O
the	O
programmer	O
to	O
ensure	O
that	O
no	O
mutable	B-Application
references	O
exist	O
.	O
</s>
<s>
The	O
type	O
string	O
is	O
an	O
alias	O
for	O
immutable(char )	O
[],	O
i.e.	O
</s>
<s>
a	O
typed	O
slice	O
of	O
memory	B-General_Concept
of	O
immutable	B-Application
characters	O
.	O
</s>
<s>
Objects	O
of	O
type	O
const(char )	O
 [  ] 	O
can	O
refer	O
to	O
strings	O
,	O
but	O
also	O
to	O
mutable	B-Application
buffers	O
.	O
</s>
<s>
Making	O
a	O
shallow	O
copy	O
of	O
a	O
const	O
or	O
immutable	B-Application
value	I-Application
removes	O
the	O
outer	O
layer	O
of	O
immutability	B-Application
:	O
Copying	O
an	O
immutable	B-Application
string	O
(	O
immutable( char[]	O
)	O
)	O
returns	O
a	O
string	O
(immutable(char )	O
 [  ] 	O
)	O
.	O
</s>
<s>
The	O
immutable	B-Application
pointer	O
and	O
length	O
are	O
being	O
copied	O
and	O
the	O
copies	O
are	O
mutable	B-Application
.	O
</s>
<s>
The	O
referred	O
data	O
has	O
not	O
been	O
copied	O
and	O
keeps	O
its	O
qualifier	O
,	O
in	O
the	O
example	O
immutable	B-Application
.	O
</s>
<s>
There	O
is	O
nothing	O
in	O
the	O
syntax	O
of	O
the	O
declaration	O
of	O
the	O
class	O
String	O
that	O
enforces	O
it	O
as	O
immutable	B-Application
;	O
rather	O
,	O
none	O
of	O
the	O
String	O
class	O
's	O
methods	O
ever	O
affect	O
the	O
data	O
that	O
a	O
String	O
object	O
contains	O
,	O
thus	O
making	O
it	O
immutable	B-Application
.	O
</s>
<s>
The	O
keyword	O
final	O
(	O
detailed	O
article	O
)	O
is	O
used	O
in	O
implementing	O
immutable	B-Application
primitive	O
types	O
and	O
object	O
references	O
,	O
but	O
it	O
cannot	O
,	O
by	O
itself	O
,	O
make	O
the	O
objects	O
themselves	O
immutable	B-Application
.	O
</s>
<s>
Reference	O
types	O
cannot	O
be	O
made	O
immutable	B-Application
just	O
by	O
using	O
the	O
final	O
keyword	O
.	O
</s>
<s>
Primitive	B-Language
wrappers	I-Language
(	O
Integer	O
,	O
Long	O
,	O
Short	O
,	O
Double	O
,	O
Float	O
,	O
Character	O
,	O
Byte	O
,	O
Boolean	O
)	O
are	O
also	O
all	O
immutable	B-Application
.	O
</s>
<s>
Immutable	B-Application
classes	O
can	O
be	O
implemented	O
by	O
following	O
a	O
few	O
simple	O
guidelines	O
.	O
</s>
<s>
In	O
JavaScript	B-Language
,	O
all	O
primitive	O
types	O
(	O
Undefined	O
,	O
Null	O
,	O
Boolean	O
,	O
Number	O
,	O
BigInt	O
,	O
String	O
,	O
Symbol	O
)	O
are	O
immutable	B-Application
,	O
but	O
custom	O
objects	O
are	O
generally	O
mutable	B-Application
.	O
</s>
<s>
To	O
simulate	O
immutability	B-Application
in	O
an	O
object	O
,	O
one	O
may	O
define	O
properties	O
as	O
read-only	O
(	O
writable	O
:	O
false	O
)	O
.	O
</s>
<s>
Alternatively	O
,	O
one	O
may	O
use	O
to	O
make	O
existing	O
objects	O
immutable	B-Application
.	O
</s>
<s>
With	O
the	O
implementation	O
of	O
,	O
JavaScript	B-Language
has	O
the	O
ability	O
to	O
create	O
immutable	B-Application
references	O
that	O
cannot	O
be	O
reassigned	O
.	O
</s>
<s>
However	O
,	O
using	O
a	O
const	O
declaration	O
does	O
n't	O
mean	O
that	O
value	O
of	O
the	O
read-only	O
reference	O
is	O
immutable	B-Application
,	O
just	O
that	O
the	O
name	O
cannot	O
be	O
assigned	O
to	O
a	O
new	O
value	O
.	O
</s>
<s>
The	O
use	O
of	O
immutable	B-Application
state	O
has	O
become	O
a	O
rising	O
trend	O
in	O
JavaScript	B-Language
since	O
the	O
introduction	O
of	O
React	B-Application
,	O
which	O
favours	O
Flux-like	O
state	O
management	O
patterns	O
such	O
as	O
Redux	B-Language
.	O
</s>
<s>
In	O
Perl	B-Language
,	O
one	O
can	O
create	O
an	O
immutable	B-Application
class	I-Application
with	O
the	O
Moo	O
library	O
by	O
simply	O
declaring	O
all	O
the	O
attributes	O
read	O
only	O
:	O
</s>
<s>
Creating	O
an	O
immutable	B-Application
class	I-Application
used	O
to	O
require	O
two	O
steps	O
:	O
first	O
,	O
creating	O
accessors	O
(	O
either	O
automatically	O
or	O
manually	O
)	O
that	O
prevent	O
modification	O
of	O
object	O
attributes	O
,	O
and	O
secondly	O
,	O
preventing	O
direct	O
modification	O
of	O
the	O
instance	O
data	O
of	O
instances	O
of	O
that	O
class	O
(	O
this	O
was	O
usually	O
stored	O
in	O
a	O
hash	O
reference	O
,	O
and	O
could	O
be	O
locked	O
with	O
Hash::Util	O
'	O
s	O
lock_hash	O
function	O
)	O
:	O
</s>
<s>
In	O
Python	B-Language
,	O
some	O
built-in	O
types	O
(	O
numbers	O
,	O
booleans	O
,	O
strings	O
,	O
tuples	O
,	O
frozensets	O
)	O
are	O
immutable	B-Application
,	O
but	O
custom	O
classes	O
are	O
generally	O
mutable	B-Application
.	O
</s>
<s>
To	O
simulate	O
immutability	B-Application
in	O
a	O
class	O
,	O
one	O
could	O
override	O
attribute	O
setting	O
and	O
deletion	O
to	O
raise	O
exceptions	O
:	O
</s>
<s>
The	O
standard	O
library	O
helpers	O
and	O
,	O
available	O
from	O
Python	B-Language
3.6	O
onward	O
,	O
create	O
simple	O
immutable	B-Application
classes	O
.	O
</s>
<s>
Introduced	O
in	O
Python	B-Language
3.7	O
,	O
allow	O
developers	O
to	O
emulate	O
immutability	B-Application
with	O
.	O
</s>
<s>
Racket	B-Operating_System
substantially	O
diverges	O
from	O
other	O
Scheme	B-Language
implementations	O
by	O
making	O
its	O
core	O
pair	O
type	O
(	O
"	O
cons	O
cells	O
"	O
)	O
immutable	B-Application
.	O
</s>
<s>
Instead	O
,	O
it	O
provides	O
a	O
parallel	O
mutable	B-Application
pair	O
type	O
,	O
via	O
mcons	O
,	O
mcar	O
,	O
set-mcar	O
!	O
</s>
<s>
In	O
addition	O
,	O
many	O
immutable	B-Application
types	O
are	O
supported	O
,	O
for	O
example	O
,	O
immutable	B-Application
strings	O
and	O
vectors	O
,	O
and	O
these	O
are	O
used	O
extensively	O
.	O
</s>
<s>
New	O
structs	B-Application
are	O
immutable	B-Application
by	O
default	O
,	O
unless	O
a	O
field	O
is	O
specifically	O
declared	O
mutable	B-Application
,	O
or	O
the	O
whole	O
struct	B-Application
:	O
</s>
<s>
The	O
language	O
also	O
supports	O
immutable	B-Application
hash	O
tables	O
,	O
implemented	O
functionally	O
,	O
and	O
immutable	B-Application
dictionaries	O
.	O
</s>
<s>
Rust	O
's	O
ownership	O
system	O
allows	O
developers	O
to	O
declare	O
immutable	B-Application
variables	O
,	O
and	O
pass	O
immutable	B-Application
references	O
.	O
</s>
<s>
By	O
default	O
,	O
all	O
variables	O
and	O
references	O
are	O
immutable	B-Application
.	O
</s>
<s>
Mutable	B-Application
variables	I-Application
and	O
references	O
are	O
explicitly	O
created	O
with	O
the	O
mut	O
keyword	O
.	O
</s>
<s>
in	O
Rust	O
are	O
always	O
immutable	B-Application
.	O
</s>
<s>
In	O
Scala	B-Application
,	O
any	O
entity	O
(	O
narrowly	O
,	O
a	O
binding	O
)	O
can	O
be	O
defined	O
as	O
mutable	B-Application
or	O
immutable	B-Application
:	O
in	O
the	O
declaration	O
,	O
one	O
can	O
use	O
val	O
(	O
value	O
)	O
for	O
immutable	B-Application
entities	O
and	O
var	O
(	O
variable	O
)	O
for	O
mutable	B-Application
ones	O
.	O
</s>
<s>
Note	O
that	O
even	O
though	O
an	O
immutable	B-Application
binding	O
can	O
not	O
be	O
reassigned	O
,	O
it	O
may	O
still	O
refer	O
to	O
a	O
mutable	B-Application
object	I-Application
and	O
it	O
is	O
still	O
possible	O
to	O
call	O
mutating	O
methods	O
on	O
that	O
object	O
:	O
the	O
binding	O
is	O
immutable	B-Application
,	O
but	O
the	O
underlying	O
object	O
may	O
be	O
mutable	B-Application
.	O
</s>
<s>
defines	O
an	O
immutable	B-Application
entity	O
maxValue	O
(	O
the	O
integer	O
type	O
is	O
inferred	O
at	O
compile-time	B-Application
)	O
and	O
a	O
mutable	B-Application
entity	O
named	O
currentValue	O
.	O
</s>
<s>
By	O
default	O
,	O
collection	O
classes	O
such	O
as	O
List	O
and	O
Map	O
are	O
immutable	B-Application
,	O
so	O
update-methods	O
return	O
a	O
new	O
instance	O
rather	O
than	O
mutating	O
an	O
existing	O
one	O
.	O
</s>
<s>
While	O
this	O
may	O
sound	O
inefficient	O
,	O
the	O
implementation	O
of	O
these	O
classes	O
and	O
their	O
guarantees	O
of	O
immutability	B-Application
mean	O
that	O
the	O
new	O
instance	O
can	O
re-use	O
existing	O
nodes	O
,	O
which	O
,	O
especially	O
in	O
the	O
case	O
of	O
creating	O
copies	O
,	O
is	O
very	O
efficient	O
.	O
</s>
