Caché ObjectScript is an object programming language designed for rapidly developing complex business applications. It is well-suited for a variety of applications including:
Caché ObjectScript source code is compiled into object code that executes within the Caché Virtual Machine. This object code is highly optimized for operations typically found within business applications, including string manipulations and database access. ObjectScript programs are completely portable across all platforms supported by Caché.
You can use Caché ObjectScript in any of the following contexts:
Caché ObjectScript is completely compatible and interoperable with Caché's other native scripting language, Caché Basic.
To learn more about Caché ObjectScript, you can also refer to:
Features
Some of the key features of Caché ObjectScript include:
Language Overview
The following is an introduction to the major elements of Caché ObjectScript.
Caché ObjectScript does not define any reserved words: you are free to use any word as an identifier (such as a variable name). In order to accomplish this, Caché ObjectScript uses a set of built-in commands as well as special characters (such as the “$” prefix for function names) in order to distinguish identifiers from other language elements.
For example, to assign a value to a variable, you can use the SET command:
 SET x = 100
 WRITE x
 
In Caché ObjectScript it is possible (though not recommended) to use any valid name as an identifier name, as shown in the following program, which is functionally identical to the previous example:
 SET SET = 100
 WRITE SET
 
Some components of Caché ObjectScript, such as command names and function names, are case-insensitive. Other components of Caché ObjectScript, such as variable names and method names, are case-sensitive. For details refer to the Syntax chapter of this document.
Note that whitespace can be inserted or omitted almost anywhere in Caché ObjectScript. However, one use of whitespace is significant; a statement cannot start on the first character position on a line. Thus, all commands must be indented. Comments must also be indented. The only code element that can appear in the first character position on a line is a label:
MyLabel
 SET x = 100
 WRITE x
 
Whitespace rules are further discussed in the Syntax chapter of this document.
Invoking Commands and Functions
ObjectScript syntax, in its simplest form, involves invoking commands on expressions, such as:
 WRITE x
which invokes the WRITE command on the variable x (this displays the value of x). In the example above, x is an expression; an ObjectScript expression is one or more “tokens” that can be evaluated to yield a value. Each token can be a literal, a variable, the result of the action of one or more operators (such as the total from adding two numbers), the return value that results from evaluating a function, some combination of these, and so on. The valid syntax for a statement involves its commands, functions, and operators and expressions; see each chapter for information on these.
Statements and Commands
A Caché ObjectScript program consists of a number of statements. Each statement defines a specific action for a program to undertake. Each statement consists of a command and its arguments.
Consider the following ObjectScript statement:
 SET x="World"
 WRITE "Hello",!,x
 
WRITE is a command. It does exactly what its name implies: it writes whatever you specify as its argument(s) to the current principal output device. In this case, WRITE writes three arguments: the literal string “Hello”; the “!” character, which is a symbolic operator specific to the WRITE command that issues a line feed/carriage return; and the local variable x, which is replaced during execution by its current value. Arguments are separated by commas; you may also add whitespace between arguments (with some restrictions). Whitespace is discussed in the Syntax chapter of this document.
Most Caché ObjectScript commands (and many functions and special variables) have a long form and a short (abbreviated) form (typically one or two characters). For example, the following program is identical to the previous one, but uses the abbreviated command names:
 S x="World"
 W "Hello",!,x
 
The short form of a command name is simply a device for developers who do not like to type long command names. It is exactly equivalent to the long form. This document uses the long form of command names. For a complete list, see Abbreviations Used in Caché ObjectScript in the Caché ObjectScript Reference.
For more information on commands, refer to the Commands chapter or the individual reference page within the Caché ObjectScript Reference.
Functions
A function is a routine that performs a frequently-required operation (for example, converting a string to its equivalent ASCII code values). A function is invoked within a command line. This invocation passes parameters to the function, which uses these parameter values to perform some operation. The function then returns a single value that is the result of the operation. You can use a function any place you can use an expression. A function invoked upon an object is called a method. (Expressions and methods are described later in this chapter.)
In addition to its system-supplied functions, Caché ObjectScript allows you to write “procedures,” which are user-defined functions. The system-supplied functions are provided as part of Caché; they perform common string and data operations and each is described in the Caché ObjectScript Reference. For information on defining and calling user-defined functions, refer to User-Defined Code.
Expressions
An expression is any set of tokens that can be evaluated to yield a single value. For example, the literal string, “hello”, is an expression. So is l + 2. Variables such as x, functions such as $LENGTH(), and special variables such as $ZVERSION also evaluate to an expression.
Within a program, you use expressions as arguments for commands and functions:
 SET x = "Hello"
 WRITE x,!
 WRITE 1 + 2,!
 WRITE $LENGTH(x),!
 WRITE $ZVERSION
 
Variables
In ObjectScript, a variable is the name of a location in which a runtime value can be stored. Variables must be defined, for example, by using the SET command, but they do not have to be typed. Variables in Caché ObjectScript are untyped; that is, they do not have an assigned data type and can take any data value. (For compatibility, the $DOUBLE function can be used to convert untyped floating point numbers to a specific numeric data type format.)
Caché ObjectScript supports several kinds of variables:
Caché ObjectScript supports various operations on or among variables. Variable are described in much greater detail in the Variables chapter of this document.
Operators
Caché ObjectScript defines a number of built-in operators. These include arithmetic operators, such as addition (“+”) and multiplication (“*”), logical operators, and pattern match operators. For details, refer to the Operators chapter of this document.
Relationship with ANSI Standard M
Caché ObjectScript is a functional superset of the ANSI-standard M programming language. If you are an M programmer you can run your existing M applications on Caché with little or no change.
Caché ObjectScript offers a number of significant improvements over ANSI-standard M including:
You can take advantage of these new features in an evolutionary fashion, using them within your applications as you see fit.