Take advantage of new Synergy Language features
Synergy/DE 9 contains important and useful new language features. Some of the major additions that have not yet been covered in Synergy-e-News are INIT, DATA, several new data types, and unsigned integer operators.
The INIT statement is an improvement over the CLEAR statement in that it will initialize each individual field in a named data structure with its initial value (either the declared default value or the default for the specified type if no value is declared), whereas CLEAR initializes the whole area based on the default value for the variable’s data type. In addition, you can use INIT on structure parameters. (It also works automatically with the new int data type, while some casting is required to make CLEAR work with int.) Use INIT whenever at least one variable in a record has a default value.
For example,
structure struct1
fld1 ,d4 ,7
enstructure
record
svar ,struct1
record vars
alp1 ,a5
alp2 ,a11, “Hello World”
alp3 ,a25
proc
; Difference between CLEAR and INIT
clear svar ;Sets svar.fld1 to 0
init svar ;Sets svar.fld1 to 7
; Insert values into the variables in record vars
init vars ;Restores default values (spaces) for
; alpha variables alp1 and alp3 and
; restores the variable alp2’s initial
; value (in this case, “Hello World”)
The DATA statement allows data to be defined inside the procedure division. The scope of the data defined exists only inside the BEGIN-END block in which it is defined. The new DATA statement is very useful for variables that do not need to exist beyond the scope of the block of code in which they are created.
For example,
proc
if var
begin
data datetime ,a20 ;Variable that will exist only
; in this BEGIN-END block
.
.
.
writes(chan, “Variable var true at ”+ datetime)
end
For future compatibility with .NET, we added the following new data types in version 9: decimal, string, byte, short, int, and long. These types are automatically mapped to compatible Synergy types. The table below lists the new data types with the existing Synergy types they are mapped to and their default values.
New data type |
Mapped to existing Synergy type |
Default value |
Decimal |
Equivalent to d28.10 |
Array of character “0” (zero) of size 28 |
String
(@System.String) |
String class |
^NULL |
Byte |
i1 (signed 8-bit integer) |
0 |
Short |
i2 (signed 16-bit integer) |
0 |
Int |
i4 (signed 32-bit integer) |
0 |
Long |
i8 (signed 64-bit integer) |
0 |
For example,
myint ,i4
is equivalent to
myint ,int
Version 9 also includes the following unsigned integer operators, which can be used in comparison operations between unsigned integer values:
Operator |
Description |
.EQU. |
Unsigned integer equal to |
.NEU. |
Unsigned integer not equal to |
.GTU. |
Unsigned integer greater than |
.LTU. |
Unsigned integer less than |
.GEU. |
Unsigned integer greater than or equal to |
.LEU. |
Unsigned integer less than or equal to |
For example,
record
int1 ,i4 ,1
int2 ,i4 ,2
proc
if %unsigned(int1) .NEU. %unsigned(int2)
writes(chan,”Unsigned integers not equal”)
The addition of INIT, DATA, the new .NET-compatible data types, and unsigned integer operators to Synergy Language allows for more creative, efficient, and modern code. We encourage you to become familiar with the use and purpose of these new features. See the Synergy/DE 9 Web site for more information about Synergy/DE 9.
|