Special operators

Lists the special operators in OPL and their syntax.

Table 1. Special operator syntax
Syntax Effect
new constructor(arg1, ..., argn)

Calls the constructor with the given arguments, and returns the created value.

Examples:

new Array() new MyCar("Ford", 1975)

The constructor is typically a script variable reference, but it can be any expression.

Example:

new ctors[i](arg) // Invokes constructor ctors[i]
typeof value

Returns a string representing the type of value, as follows:

Array "object" Boolean "boolean" Date "date" Function "function" Null "object" Number "number" Object "object" String "string" Undefined "undefined"
delete variable

Deletes the global script variable variable. This does not mean that the value in variable is deleted, but that it is removed from the global environment.

Example:

myVar = "Hello, world" // Create the global variable myVar delete myVar writeln(myVar) // Signals an error because myVar is undefined

If variable is a local variable, an error is signalled; if variable is not a known variable, nothing happens.

The whole expression returns true.

For C/C++ programmers: The delete operator has a radically different meaning in IBM ILOG Script; in C++, it is used to delete objects, not script variables and properties.

delete value.name

delete value[name]

Remove the property name from the object value.

If value does not contain the name property, this expression does nothing. If the property does exist but cannot be deleted, an error is signalled. If value is not an object, an error is signalled.

The whole expression returns the true value.

expression1 , expression2

Evaluates expression1 and expression2 sequentially, and returns the value of expression2. The value of expression1 is ignored.

The most common use for this operator is inside for loops, where it can be used to evaluate several expressions where a single expression is expected:

for (var i=0, j=0; i<10; i++, j+=2)
{  writeln(j, " is twice as big as ", i); }