Enforced immutability: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 239:
Constants in COBOL are not stored in memory, but are closer to C's macros, by associating a literal with a name.
Prior to COBOL 2002, you could define figurative literals for characters only:
<syntaxhighlight lang="cobol"> ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9.</syntaxhighlight>
A new syntax was introduced in COBOL 2002 which allowed defining constants for other types.
<syntaxhighlight lang="cobol"> 01 Foo CONSTANT AS "Foo".</syntaxhighlight>
Prior to COBOL 2002, there were non-standard extensions available that also implemented constants. One extension was the the 78 level-number:
<syntaxhighlight lang="cobol"> 78 Foo VALUE "Foo".</syntaxhighlight>
Another was the <code>CONSTANT SECTION</code>:
<syntaxhighlight lang="cobol"> CONSTANT SECTION.
01 Foo VALUE "Foo".</syntaxhighlight>
=={{header|D}}==
Line 757:
</syntaxhighlight>
====
The value of a enumeration type may change to those of the same type (not the value type, the variable type)
Line 1,527:
Note though that if fields are reference types (lists, maps, user-defined classes etc.) even a 'getter' method may enable their internal state to be mutated unless you copy them first.
<syntaxhighlight lang="
construct new(f) {
_f = f // sets field _f to the argument f
Line 1,552:
{{libheader|Wren-trait}}
Since the above entry was written, a ''Const'' class has been added to ''Wren-trait'' which simulates constants to some extent though the values used need themselves to be immutable for this to be water-tight.
<syntaxhighlight lang="
Const["six"] = 6
|