Difference between revisions of "Declaredtype"

From Mesham
Jump to navigationJump to search
(Created page with '== Syntax == declaredtype varname; == Semantics == Will return the declared type of the variable. == Example == var i:Int; i:i::const[]; i:declaredtype i; [[Category:…')
 
m (5 revisions imported)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Syntax ==
 
== Syntax ==
  
declaredtype varname;
+
declaredtype name
 +
 
 +
Where ''name'' is a variable name
  
 
== Semantics ==
 
== Semantics ==
  
Will return the declared  type of the variable.
+
Will return the declared  type of the variable.<br><br>
 +
''Note:'' This is a static construct only and its lifetime is limited to during compilation.
  
 
== Example ==
 
== Example ==
  
  var i:Int;
+
  function void main() {
i:i::const[];
+
    var i:Int;
i:declaredtype i;
+
    i:i::const[];
 +
    i:declaredtype i;
 +
};
 +
 
 +
This code example will firstly type ''i'' to be an [[Int]]. On line 2, the type of ''i'' is combined with the type [[const]] (enforcing read only access to the variable's data.) On line 3, the programmer is reverting the variable back to its declared type (i.e. so one can write to the data.)
 +
 
 +
''Since: Version 0.5''
  
 
[[Category:Sequential]]
 
[[Category:Sequential]]
 
[[Category:Types]]
 
[[Category:Types]]

Latest revision as of 15:44, 15 April 2019

Syntax

declaredtype name

Where name is a variable name

Semantics

Will return the declared type of the variable.

Note: This is a static construct only and its lifetime is limited to during compilation.

Example

function void main() {
   var i:Int;
   i:i::const[];
   i:declaredtype i;
};

This code example will firstly type i to be an Int. On line 2, the type of i is combined with the type const (enforcing read only access to the variable's data.) On line 3, the programmer is reverting the variable back to its declared type (i.e. so one can write to the data.)

Since: Version 0.5