Skip to content

Commit

Permalink
Merge pull request JuliaLang#7873 from StephenVavasis/patch-3
Browse files Browse the repository at this point in the history
more explanation of immutable
  • Loading branch information
quinnj committed Aug 19, 2014
2 parents 09406a3 + 442aaa5 commit 472324d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/manual/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,29 @@ would be considered identical, or if they might need to change independently
over time. If they would be considered identical, the type should probably
be immutable.

To recap, two essential properties define immutability
in Julia:

* An object with an immutable type is passed around (both in assignment
statements and in function calls) by copying, whereas a mutable type is
passed around by reference.

* It is not permitted to modify the fields of a composite immutable
type.

It is instructive, particularly for readers whose background is C/C++, to consider
why these two properties go hand in hand. If they were separated,
i.e., if the fields of objects passed around by copying could be modified,
then it would become more difficult to reason about certain instances of generic code. For example,
suppose ``x`` is a function argument of an abstract type, and suppose that the function
changes a field: ``x.isprocessed = true``. Depending on whether ``x`` is passed by copying
or by reference, this statement may or may not alter the actual argument in the
calling routine. Julia
sidesteps the possibility of creating functions with unknown effects in this
scenario by forbidding modification of fields
of objects passed around by copying.


Declared Types
--------------

Expand Down

0 comments on commit 472324d

Please sign in to comment.