Yes, I know, I've seen this discussed a few times...
It seems like some of the issues (primarily related to how it would fit with pascal syntax) are:
- What would it look like? Would it be a something other than var?
- Would it be an attribute to var?
- How would initial assignment be done?
Doing complex initial assignment in the var section (especially if it uses parameters from parent function or needs to make function calls is tedious...).
If with additional keywords it something like the following could work within existing pascal syntax (suggested names are just example names, not necessarily what I'm suggesting):
program immutable;
procedure something (const a, b, c: integer);
var
d: integer; immutable;
e: integer; immutable;
f: integer; immutable;
begin
d := a + 4; final;
e := b + 5; final;
f := c + 6; final;
writeln ('a: ', a);
writeln ('b: ', b);
writeln ('c: ', c);
writeln ('d: ', d);
writeln ('e: ', e);
writeln ('f: ', f);
end;
begin
something (1, 2, 3);
end.
Using the
immutable keyword, the
final keyword would not likely not be used.
Basically with
immutable the first assignment would lock in the value, and the compiler would not allow for further assignment.
If there was enough community and developer buy in to to such a feature change, I might be willing to do a lot of the legwork, providing I'd get sufficient assistance.