2.02 Data Control

Var

Var is used to define a variable.

A variable that is declared and used only within a procedure or within the root segment is local to that procedure and is not the same as any other variable of the same name used elsewhere in the source module. Alternatively, a variable in the root segment may be declared as shared and be available throughout the source module.

The value of a local variable within a procedure or function is reset each time the procedure or function is called. A variable that is defined within the root segment is static for the duration of the program.

Within a procedure or function, where a local variable has the same name as a shared variable, the local variable will be used in preference.

Description:

Defines a variable as local to a procedure or function and optionally assigns a value.

Syntax:

[var] [[as] type] name [= expr] [, name [= expr]] …
[var] name [= expr] [, name [= expr]] … [[as] type]

where:

type
the type of the variable. This may be left out.

If it is possible that the type could be confused with a variable name, it should be prefixed with the keyword as.
name
the name of the variable.
expr
The expression to be evaluated and assigned to the variable.

Notes:

The keyword var may be omitted if the type is specified.

If the type is not specified but there is an assignment, the type is determined from the assigned value. The value may be a literal or may be an expression.

  • If the value is an integer the type is set to xgen32(xlong).
  • If the value is a numeric literal containing a decimal point or the result of the expression contains a fraction the type set to is double.
  • Any other value causes the type to be set to string.

If the type is not specified and there is no assignment, the type is set to xgen32(xlong).

The keyword local is currently supported in some implementations as a synonym for var. This is deprecated and will be dropped in a future release. It only applies to local variables within a procedure or function. If used in the root segment it will be ignored. It will not cause an error.

Let

Description:

Assigns a value to a variable.

Syntax:

[let] name = expr

where:

name
the name of the variable.
expr
The expression to be evaluated and assigned to the variable.

Notes:

The word let is optional.

A variable can be cleared back to the default value by omitting the expression completely.

Example:

aa = {1,2,3,4,5}      // assign an array

aa =                  // reset the variable

Let Function

Description:

Assigns a value to a variable and returns the value

Syntax:

let(name, expr)

where:

name
the name of the target variable.
expr
The expression to be evaluated and assigned to the variable.

Notes:

Example:

put let(aa, {1,2,3,4,5})  // assigns values to an array and then displays {1,2,3,4,5}

Const

Description:

Assigns a constant value to a name.

Syntax:

const name = expr

where:

name
the name of the constant.
expr
The expression to be evaluated and assigned to the constant.

Notes:

Enum

Description:

Assigns a series of constant values to a series of names.

Syntax:

enum [start]
name1 [= value]
name2
end enum

where:

start
The value to be assigned to the first entry in the list.
value
A value to be assigned to this entry. Each subsequent value will be an increment from this.

Notes:

See Also


lynplex/lp0202.txt · Last modified: 2012/08/22 13:05 (external edit)