Professional Documents
Culture Documents
This article's tone or style may not reflect the encyclopedic tone used on
Wikipedia. See Wikipedia's guide to writing better articles for
suggestions. (December 2012) (Learn how and when to remove this template message)
TTM
License MIT
Major implementations
Unidata TTM
Influenced by
TRAC
TTM is a string oriented, general purpose macro processing programming language developed in
1968 by Steven Caine and E. Kent Gordon at the California Institute of Technology.
Contents
1Description
2Syntax and Semantics
o 2.1Function definition
o 2.2Escaping
3Examples
o 3.1Example 1: Function Definition
o 3.2Example 2: Factorial
4See also
5Notes
6References
7External links
Description[edit]
The following description is taken from the original TTM reference manual [1] and the subsequent
batch processing extension.[2]
TTM Is a recursive, interpretive language designed primarily for string manipulation, text editing,
macro definition and expansion, and other applications generally classified as systems
programming. It is derived, primarily, from GAP[3] and GPM.[4]
Initially, TTM was planned as the macro processing portion of an assembler for the IBM System/360
and, as such, was designed to overcome the restrictions and inconsistencies which existed in the
standard assemblers for that system.[5][6]
In addition, it was designed to have all of the power possessed by earlier general macro assemblers
but with the unfortunate syntactic and semantic difficulties removed.[7][8][9][10]
During the development of TTM, it became apparent that applications other than assembler macro
processing were possible. These include data editing, text manipulation, expression compiling, and
macro processing for language processors other than assemblers.
The initial version of TTM was implemented to run in a conversational manner under the Caltech
Basic Time Sharing System for the IBM System/360 Model 50.[11] Other versions have been written
to run in the batch processing environment of OS/360 and to operate in front of or in conjunction with
various language processors.
#<functionname;arg1;arg2;...;argn>
where the function name and the arguments are arbitrary character strings not containing characters
of significance: '#', '<', '>', and ';'. The function is invoked with the specified arguments and the
resulting text is inserted into the original text in place of the function call. If the function call was
prefixed by a single '#' character, then scanning will resume just before the inserted text from the
function call.
This is called active invocation.
If the function call was prefixed by two '#' characters, then scanning resumes just after the inserted
text. This is called passive invocation.
During the collection of a function call, additional function calls may be encountered, for example,
this.
#<functionname;arg1;#<f2;arg;...>;...;argn>
The nested function call will be invoked when encountered and the result inserted into the text of the
outer function call and scanning of the outer function call resumes at the place indicated by the
number of '#' characters preceding the nested call.
If a function takes, for example, 2 arguments, any extras are ignored. For user defined functions, if
too few arguments are provided, additional one are added with the value of the empty string (""). A
function may have a maximum of 62 arguments.
As with other applicative programming languages, a TTM function may be recursive and may be
defined as the result of the invocation of a sequence of other function calls.
Functions are either built-in or user defined. A large number of built-in functions exist and are
defined in the TTM reference manual [1]
Function definition[edit]
User defined functions are created using the following two built-in functions.
#<ds;name;text>
#<ss;name;text1;text2...;textn>
The first function, ds for "define string", defines a named string in the TTM dictionary. The name is
"name" and its value is "text". Invoking this named string will cause its invocation to be replaced by
the value (i.e. "text").
The second function, ss for "segment string", scans the text of a previously defined string looking for
occurrences of its arguments: text1, text2, ... textn. When an occurrence is found, it is replaced with
a segment mark. All occurrences of each argument are replaced by the same segment mark.
When a segmented string is invoked, each argument to the call is substituted for the corresponding
segment mark. Consider this example.
[01] #<ds;F;abcxxdefyy>
[02] #<ss;F;xx;yy>
[03] #<F;11;22>
The string F is defined (line 1) and its body "abcxxdefyy" is segmented on the two strings "xx" and
"yy" (line2). When invoked (line 3), it will return the value "abc11def22". In effect, we have a user
defined function F with two arguments.
Escaping[edit]
It is possible to escape one or more characters using either of two conventions.
Examples[edit]
Example 1: Function Definition