You can invoke the Gamma engine by typing
[sh]$gamma
at the shell prompt.
It will return the following Gamma prompt:
Gamma>
Now you can start writing instructions to the Gamma engine and get an
immediate response. If you define a variable a without
assigning it a value, the Gamma engine will respond with the message that the
symbol is undefined and suggest debugging:
Gamma>a;Symbol is undefined: a debug 1>
Type Ctrl - D to return to the Gamma
prompt and assign a a value:
Gamma>a = 5;5Gamma>
This time the Gamma engine responds with the value assigned to the variable. In
a Gamma program a variable must be assigned a value. The library function
undefined_p can be used to test if a variable is
defined:
Gamma>undefined_p (b);tGamma>b = 1;1Gamma>undefined_p (b);nilGamma>
This function returns t for
true and nil for false. The
objects t and nil are discussed in
more detail in the Logical Types section
of the Basic Data Types and Mechanisms chapter.
A function is defined in the Gamma language using a function statement:
Gamma>function MyFunc (a) { a *= 10;}(defun MyFunc (a) (*= a 10))Gamma>
The Gamma engine returns the function definition in Lisp syntax. It reflects
the fact that a Gamma program is using the Lisp engine internally. Basically,
Lisp displays functions as lists, surrounded by parentheses. The first word in
every Gamma function definition is defun because that is
the Lisp function for defining functions. After that, the function name is
listed, followed by its arguments and code, which is also in Lisp format.
The MyFunc function called with 12 as its argument will
return the value 120, as follows:
Gamma>MyFunc (12);120Gamma>
Notice that no type specification is used. An important feature of the Gamma language is that it is an abstractly typed language, making it unnecessary to specify the type of a data object in order to be able to use it. This does not mean that objects do not have types, but rather the system does not require that the type of an object be known until the code actually executes. This allows a function to return entirely different types, depending on what the calculation produces.
For example, a MIN function could be defined as:
function min (x, y) { if (x < y) x; else y; }
This function will return an integer or floating point number depending on the types of the arguments. The arguments do not need to be the same type. The Gamma engine automatically type-casts them, favoring the smallest possible memory allocation. However, the less-than comparison will fail if both arguments are not numeric types.
Finally, return statements are not necessary in a Gamma
program. Looking at the function MyFunc, we see it returns 120, the result of
multiplying a by 10. Any Gamma function that executes
successfully always returns a value, which is the result of evaluating the last
expression in the function. This return value determines the value and type of
the function.
This topic is discussed in greater detail in Function Definitions in the Functions and Program Structure chapter.