Difference between revisions of "Const"

From Mesham
Jump to navigationJump to search
m
m (4 revisions imported)
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
 
== Example ==
 
== Example ==
  
  var a:Int;
+
  function void main() {
a:=34;
+
    var a:Int;
a:(a :: const[]);
+
    a:=34;
a:=33;
+
    a:(a :: const[]);
 +
    a:=33;
 +
};
  
 
The code in the above example will produce an error. Whilst the first assignment (''a:=34'') is legal, on the subsequent line the programmer has modified the type of ''a'' to be that of ''a'' combined with the type ''const''. The second assignment is attempting the modify a now read only variable and will fail.
 
The code in the above example will produce an error. Whilst the first assignment (''a:=34'') is legal, on the subsequent line the programmer has modified the type of ''a'' to be that of ''a'' combined with the type ''const''. The second assignment is attempting the modify a now read only variable and will fail.

Latest revision as of 15:44, 15 April 2019

Syntax

const[ ]

Semantics

Enforces the read only property of a variable.

Example

function void main() {
   var a:Int;
   a:=34;
   a:(a :: const[]);
   a:=33;
};

The code in the above example will produce an error. Whilst the first assignment (a:=34) is legal, on the subsequent line the programmer has modified the type of a to be that of a combined with the type const. The second assignment is attempting the modify a now read only variable and will fail.

Since: Version 0.41b