Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Declaring data"

(Removing all content from page)
 
Line 1: Line 1:
<br>
 
  
EGL native types are in three categories: <br>
 
 
:[[Declaring data#Values_of_simple_value_types|Simple value types]]:
 
 
::BigInt, Date, Decimal(''n''), Decimal(''n'', ''p''),
 
 
::Float, Int, SmallFloat, SmallInt, Timestamp(''pattern'')
 
 
:[[Declaring data#Values_of_simple_reference_types|Simple reference types]]:
 
 
::Decimal, Number, String (now a value type),
 
 
::Timestamp (now a value type)
 
 
:Other reference types:
 
 
::[[EDT:Declaring data#Any|Any]], [[Declaring data#Dictionary|Dictionary]], [[Declaring data#List|List]]
 
 
<br>Note:&nbsp;
 
 
*The '''as''' operator casts a value from one type to another.&nbsp;
 
*The '''isa''' operator tests whether a value is of a given type.&nbsp;
 
 
<br>See also [[Working with custom types|Working with custom types]].
 
 
<br>
 
 
= <br> '''Values of simple value types'''  =
 
 
<source lang="java">
 
/** Character value types. **/
 
/** Note: String without parameter will be a reference type in EDT 1.0. **/
 
 
// Defaults to an empty string.
 
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;
 
 
// Initializes the date to 30 January 2015.
 
future Date = "01/30/2015";
 
 
// Defaults to now. the second declaration uses the default pattern.
 
now TIMESTAMP("ddHHmmssffffff");
 
later TIMESTAMP("yyyyMMddHHmmss");
 
 
 
/** Boolean type **/
 
 
// Defaults to false.       
 
toggle Boolean;           
 
</source>
 
 
= Values of simple reference types  =
 
 
<source lang="java">
 
 
 
</source>
 
 
= Values of type Any  =
 
 
<source lang="java">
 
 
 
</source>
 
 
= Values of type Dictionary  =
 
 
<source lang="java">
 
// initializes a dictionary with 3 key/value pairs. 
 
// By default, the keys are case insensitive.
 
myRef Dictionary {
 
  driverID  = 5,
 
  lastName  = "Twain",
 
  firstName = "Mark"
 
};
 
 
// adds new key/value pairs to the dictionary
 
myRef.age = 30;
 
myRef["Credit"] = 700;
 
 
// overrides an existing key/value pair
 
myRef.lastname = "Clemens";
 
 
 
</source>
 
 
<br>
 
 
<br>
 
 
= Values of type List  =
 
 
<source lang="java">
 
 
// declares a new list, disallowing nulls.
 
vals Int[];             
 
 
// declares a new list, allowing nulls.
 
nullVals Int[];
 
 
// declares a new list, adds 30 elements, and initializes each element to zero.
 
newVals Int[] = new Int[30];
 
 
// declares a list of 4 strings by use of a set-values block
 
departurePhrase  STRING[] = ["goodbye", "ciao"];
 
 
// assigns the first index in the array to "au revoir"
 
departurePhrase[1] = "au revoir";                             
 
 
// assigns the last index in the list to "auf wiedersehen".         
 
departurePhrase[departurePhrase.getSize()] = "auf wiedersehen";               
 
 
// initializes a list of 3 integers
 
integerList    INT[] = [1,2,3];
 
 
// initializes a list of 2 booleans
 
booleanList    BOOLEAN[] = [ (10000 > 50000), (10000 < 50000) ]; 
 
 
initializes a 2-dimensional list; that is, a list of lists
 
the2Dimension  INT[][] = [[1,2],[3,4]];
 
 
// creates a value in which the element values are changeable,
 
// but the name MINIMUMNUMBERS cannot refer to another list.
 
const MINIMUMNUMBERS INT[] = [1,2,3,4,5];
 
 
// declares another list of strings.
 
cities String[];             
 
 
// appends a new value to the end of the list.           
 
cities.appendElement("Delta");   
 
 
// appends two new values to the end of the list.
 
cities.appendAll([ "Denver", "Pueblo" ]); 
 
 
// removes the second value in the list.
 
removeElement(2);                 
 
 
// removes all values from the list.
 
cities.removeAll();                       
 
</source>
 
 
 
<br>
 
 
<br> <br>
 
 
<br>
 

Latest revision as of 11:54, 10 February 2012

Back to the top