Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Declaring data"
Line 19: | Line 19: | ||
::[[Declaring data#Any|Any]], [[Declaring data#Dictionary|Dictionary]], [[Declaring data#List|List]] | ::[[Declaring data#Any|Any]], [[Declaring data#Dictionary|Dictionary]], [[Declaring data#List|List]] | ||
− | <br> | + | <br>Note: |
*The '''as''' operator casts a value from one type to another. | *The '''as''' operator casts a value from one type to another. |
Revision as of 17:09, 8 February 2012
EGL native types are in three categories:
- BigInt, Date, Decimal(n), Decimal(n, p),
- Float, Int, SmallFloat, SmallInt, Timestamp(pattern)
- Decimal, Number, String (now a value type),
- Timestamp (now a value type)
- Other reference types:
Note:
- The as operator casts a value from one type to another.
- The isa operator tests whether a value is of a given type.
See also Working with custom types.
Contents
Values of simple value types
/** Character value types. **/ /** Note: String without parameter will be a reference type in EDT 1.0. **/ // Defaults to "". firstName String; // Defaults to null. secondName String?; // Initializes value to "John" and allows a future value to be null. thirdName String? = "John"; // Initializes the value, which is unchangeable. // Note: the elements of constant lists and dictionaries are changeable.) const LANGUAGE String = "EGL"; /** Numeric value types. **/ // Defaults to 0. someVal Int; // Defaults to 0.0. coord Float; // Initializes value to 4.5 distance Float = 4.5; // Initializes value to 4 newDistance int = distance as int; // Defaults to 000.00. // Can hold 5 digits total, with 2 after the decimal point. amount Decimal(5,2); /** Date-and-time value types. **/ // Defaults to today's date. today Date; // Defaults to now. the second declaration uses the default pattern. now TIMESTAMP("ddHHmmssffffff"); later TIMESTAMP("yyyyMMddHHmmss"); /** Boolean type **/ // Defaults to false. toggle Boolean;
Values of simple reference types
Values of type Any
Values of type Dictionary
Values of type List
// The element values are changeable, but the name cannot refer to another list. const MINIMUMNUMBERS INT[] = [1,2,3,4,5]; // new dynamic array of size 0 vals Int[]; // dynamic list, but not instantiated (vals must be instantiated before it can be accessed) vals Int[]?; // new dynamic array of size 4; all values set to their default value (0 in this example) vals Int[] = new Int[4]; // dynamic array, initialized with 4 values names String[] = [ "Paul", "John", "George", "Ringo" ]; // assigns the first index in the array to "Bob" names[1] = "Bob"; // assigns the last index in the array to "Ken" names[names.getSize()] = "Ken"; // new dynamic array of size 0 cities String[]; // appends a new value to the end of the array cities.appendElement("Delta"); // appends two new values to the end of the list cities. cities.appendAll([ "Denver", "Pueblo" ]); // removes the second value in the array removeElement(2); // removes all values from the array cities.removeAll();