Versions Compared
Version | Old Version 8 | New Version Current |
---|---|---|
Changes made by | Former user |
Former user |
Saved on |
Key
- This line was added.
- This line was removed.
- Formatting was changed.
High Level Constructs
unitTable of Contents |
---|
Units and Functions
Units are groupings of functions and
also variables appearing in .
mez
files. They can be thought of as modules or namespaces. A
Helium app must have at least one unit.
UnitThe unit
keyword must be followed
by a unique unit name.
Units are defined as followsA unit must have at least one function.
Info |
---|
|
Status | ||||
---|---|---|---|---|
|
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
unit MyUnit;
// Other code follows
string myVar;
int factorial(int x) {
if(x == 0 || x == 1) {
return 1;
} else if (x > 1) {
return factorial(x - 1);
}
return 0;
} |
Info |
---|
Objects, enums and validators are global, so they can optionally be in a separate source code file without a unit. |
Mez File Comments
Two types of comments are supported: single line comments and multi-line comments:
Single line comments
info
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// |
date tstamp = System.now(); |
// |
decimal rand = System.random(); |
And multi-line comments:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
/* date tstamp = System.now(); |
decimal rand = System.random(); |
*/ |
Variable and Function Scope
Suppose a unit MyUnit
has a unit variable named myVar
and a function named factorial
. Both have global scope and can be accessed by any function in this or other units, e.g. from TestUnit
in the
example below. The only time a variable or custom object in the Helium DSL is not globally scoped is when it is declared inside a function and thus scoped to the function alone. To refer to a unit’s member functions or variables from another unit, you have to use the scope operator
(the colon).
Code Block | ||||
---|---|---|---|---|
| ||||
unit TestUnit; void test() { MyUnit:myVar = "New string value!"; int f = MyUnit:factorial(5); |
} |
Note: Unit variables cannot be in line initialized when they are declared. The following code will not compile
Info |
---|
|
:
Code Block | ||||
---|---|---|---|---|
| ||||
unit MyUnit;
string myVar = "some value"; // this is not a legal statement |
Additional Mentions and References
- Sections Adding a Presenter and Referencing Unit Variables and Functions in Lesson 1 of the Tutorial.
Excerpt | ||
---|---|---|
| ||
units | functions | comments | global scope |