| Tag | Resource | Value | Description |
|---|---|---|---|
| b | Buffersize | integer>0 | Set the internal buffer size. The default is 2^20 characters. The suffix m|M is allowed to indicate multiplying by 2^20. The suffix k|K is allowed to indicate multiplying by 2^10; |
| s | Stacksize | integer>0 | Set the internal stack size. The default provides for a maximum depth of 64. It is a good idea to keep this number small so that runaway recursion can be detected quickly. |
| x | Executions | integer>0 | Limit the number of executions. The default is 2^20. The purpose is to catch tail recursive executions that do not eat up space. |
python ttm.py <command line arguments>
Next, the interpreter scans the -f input file, if specified, and executes any macro invocations encountered. Any resulting output is sent to the file specified by the -o option. If not specified, the output is sent to standard output.
Finally, if the -i flag is specified, then the interpreter goes into a read-eval loop. It reads "balanced" strings from the standard input, scans the input and repeats. If no -i is specified, the interpreter exits.
The term balanced means that input is read until all instances of '<' have a matching '>'. Once balanced, input reading will stop at the currently defined EOL meta-character.
Any arguments after the file name are provided to ttm using the #<argv;i> function.
It is assumed that TTM is given a text file (via e.g. -f) containing some combination of ordinary text and TTM function calls (i.e. invocations). The text is scanned character by character. Any ordinary text is passed to the output unchanged (taking escapes into consideration). If a TTM function is encountered, it is collected and executed.
#<functionname;arg1;arg2;...;argn>where the functionname and the arguments are arbitrary character strings not 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. If the function call was prefixed by two '#' characters, then scanning resumes just after the inserted text.
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 ("").
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].
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 it's 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.
If a string is enclosed in <...>, then it is scanned but not interpreted by TTM. In the scanning process, the outer < and > brackets are removed. If there are nested occurrences of <...>, then they are scanned but the '<' and '>' are not removed. The brackets must balance: the number of '<' characters must equal the number of '>' characters. The '\' escape convention causes the interpreter to pass as-is the character after the '\'. The leading '\' is left if it within a <...> escape sequence, otherwise it is removed. One use is to allow unbalanced occurrences of '<' or '>' characters [Note: in the reference implementation, '@' was changed to '\'].
#<ds;def;<##<ds;name;<text>>##<ss;name;subs>>> #<ss;def;name;subs;text>
We can, for example, use def to define the string XX as 12345 and then segment XX on 34 by writing this.
#<def;XX;34;12345>
The call
#<XX;0000>will then produce the string "1200005".
The def function operates by invoking ds to define the function being defined — XX in our example — and then segmenting the body of XX by any specified arguments: "34" in this case. When XX is invoked, its argument is substituted for the segment mark.
#<def;n!;N;<#<lt;N;2;1;<#<mu;N;#<n!;#<su;N;1>>>>>>>Notice that the inner computation (#<mu...) is escaped so it will only be evaluated after the #<lt... function is executed and returns that nested computation as its result.
An example call would look like this.
#<n!;3>
and would return the string 6.
However, the following general changes to TTM should be noted.
| Escape Sequence | Translation |
|---|---|
| \r | carriage return |
| \n | line feed |
| \t | tab |
| \b | backspace |
| \f | form feed |
Internally, and in the C implementation, all characters are represented as 32-bit UTF characters. This wastes some space, but makes processing simpler. For Python and Java, characters are represented internally in UTF-16 because they provide native support for that format.
One more point about segment marks. It is possible using #<gn>, for example, to output a string with segment marks in it. The original documentation is silent on how such segment marks are to be treated. In this implementation, they are included. If an attempt is made to print them, they are converted to the form '^n' where n is the segment mark.
ttm
Specification: ttm,2,*,S
Invocation: #<ttm;cmd;arg1;arg2;...>
This function provides a general mechanism for embedding
special commands to extract or alter interpreter information.
The currently defined commands are as follows.
| Command | Description | ||||||
|---|---|---|---|---|---|---|---|
| #<ttm;meta;metachars> | Change the set of meta-characters. It takes one argument that specifies the set of meta characters. Setting the default behavior would use this invocation: #<ttm;meta; \#\<\;\>\\>. Note that this is separate from the CM function. | ||||||
| #<ttm;info;subcommands;...> |
Dump information about internal ttm structures.
The currently defined subcommands for info are as follows.
|
include
Specification:
argv
Specification: argv,1,1,V
Invocation:
argc
Specification: argc,0,0,V
Invocation:
classes
Specification: classes,0,0,V
Invocation:
pf
Specification: pf,0,1,S
Invocation: #<pf;stderr>
If no arguments are given, then flush stdout and stderr.
If the single argument is the string 'stderr',
then flush stderr.
If the single argument is the string 'stdout'
then flush stdout.
ad
Specification: ad,2,*,V
Invocation: #<ad;num1;...numn>
This function normally takes only two arguments.
It has been extended to take an arbitrary number
of arguments and return the sum of all of the arguments.
mu
Specification: mu,2,*,V
Invocation: #<mu;num1;...numn>
This function normally takes only two arguments.
It has been extended to take an arbitrary number
of arguments and return the product of all of the arguments.
ps
Specification: ps,1,2,S
Invocation: #<ps;string;stderr>
This function normally prints the string on
stdout. If the second argument is the string
"stderr", however, then it prints to stderr.
psr
Specification: psr,1,1,S
Invocation: #<psr;string>
This function prints its argument to stdout
and then reads from stdin up to the meta-character
(see the cm function).
cm
Specification: cm,1,1,S
Invocation: #<cm;string>
This function specifies the character
that is used to terminate input when using,
for example #<rs>.
The default meta-character has been changed
from "'" to "\n". This means that as a rule,
reading will read only a single line of input.
One can, however use the escape character
at the end of the line to read multiple lines
with the escaped '\n' being elided.
cf
Specification: cf,2,2,S
Invocation: #<cf;new-name;old-name>
The original definition said that the body of
old-name, including segment marks and beginning
at the old-name's residual pointer was copied
to the body of new-name.
However, trying to figure out how to handle
a set of segment marks with gaps is problematic.
So, the definition has been modified to
copy the whole body of the old-name
as the body of the new name, ignoring (but duplicating)
the residual pointer.
exit
Specification: exit,0,1,S
Invocation: #<exit;exitcode>
This was changed to allow optional specification
of a return code.
names
Specification: exit,0,1,V
Invocation: #<names>
This was changed so that
if the second argument is present, then
all names are returned, otherwise only non-builtin
names are returned.
tn
Specification: tn,0,*,V
Invocation: #<tn;name1;...namen>
This was changed so that only the specified function names
will be traced. If there are no names provided, then all function
invocations will be traced.
tf
Specification: tf,0,*,V
Invocation: #<tn;name1;...namen>
This was changed so that only the specified function names
will have tracing turned off. If there are no names provided, then no
function invocations will be traced. Note that turning off all tracing
will turn off tracing on all specific function.
ps
Specification: ps,1,2,S
Invocation: #<ps;string;stdxx>
This was changed to an optional allow a second argument that
specifies sending the output to either "stdout"
or "stderr". If missing, then stdout is assumed.
rs
Specification: rs,0,0,S
Invocation: #<rs>
Read a string of characters until either EOF
or the defined "end-of-input" character is reached.
rs
Specification: rs,0,0,S
Invocation: #<rs>
In order to avoid spoofing, the string 'ttm>' is printed
before reading.
The time function from the interactive version differs from that of the batch version. The interactive time function corresponds to the batch xtime function and the batch time function returns time of day instead of execution time. The batch versions of time and xtime are implemented. In additon, ctime is implemented to give time of day in Unix ctime format.
time
Specification: time,0,0,V
Invocation: #<time>
Returns the time of day in 100'ths of second
from ?.
xtime
Specification: xtime,0,0,V
Invocation: #<time>
Returns the execution time in 100'ths of second.
ctime
Specification: ctime,1,1,V
Invocation: #<ctime;time>
Convert the time (the result of a call to #<time>)
to a printable string as defined by the Unix ctime function.
A number of functions (#<gn>, $<cn>, etc.) are supposed to return some fixed number of characters. The original documentation is silent about what should happen if there are not enough characters available to return. In this implementation, whatever characters are available are returned, even if less than the number requested.
| abs,1,1,V | ad,2,2,V | ap,2,2,S | cc,1,1,SV |
| ccl,2,2,SV | cf,2,2,S | cm,1,1,S | cn,2,2,SV |
| cp,1,1,SV | cr,2,2,S | cs,1,1,SV | ctime,1,1,V |
| dcl,2,2,S | dncl,2,2,S | ds,2,2,S | dv,2,2,V |
| dvr,2,2,V | ecl,1,*,S | eos,3,3,V | eq,4,4,V |
| eq?,4,4,V | es,1,*,S | exit,0,0,S | flip,1,1,V |
| gn,2,2,V | gt,4,4,V | gt?,4,4,V | isc,4,4,SV |
| lt,4,4,V | lt?,4,4,V | mu,2,2,V | names,0,1,V |
| ndf,3,3,V | norm,1,1,V | ps,1,2,S | psr,1,1,SV |
| rrp,1,1,S | rs,0,0,V | sc,2,63,SV | scl,2,2,S |
| scn,3,3,SV | sn,2,2,S | ss,2,2,S | su,2,2,V |
| tcl,4,4,V | tf,0,0,S | time,0,0,V | tn,0,0,S |
| xtime,0,0,V | zlc,1,1,V | zlcp,1,1,V |
| rcd,2,2,S | fm,1,*,S | tabs,1,8,S | scc,2,2,S |
| icc,1,1,S | outb,0,3,S | store,2,2,S | delete,1,1,S |
| copy,1,1,S | show,0,1,S | libs,2,2,S | break,0,1,S |
The following functions from the batch ttm are not implemented.
| insw,2,2,S | ttmsw,2,2,S | cd,0,0,V | cdsw,2,2,S |
| for,0,0,V | forsw,2,2,S | pk,0,0,V | pksw,2,2,S |
| ps,1,1,S | page,1,1,S | sp,1,1,S | fm,0,*,S |
| tabs,1,10,S | scc,3,3,S | fmsw,2,2,S | des,1,1,S |
| 01 Oct. 2013 | — | Added python implementation. |
| 15 Nov. 2012 | — | Version 1.0 release with C and Java implementations. |