Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!

Language Tour - Intermediate


These features are suitable for programmers that already have some programming experience.

They are not necessary in most THT programs.

Optional Parentheses 

Functions that take zero arguments can leave out the empty parentheses.

// with empty args
function doSomething() {
    // ...

// short form
function doSomething {
   // ...

// either way, functions are always called with parens

Keyword Shortcuts 

The following one-letter shortcuts can be used instead of the full keyword.

F = function
T = template

This helps you focus more on the “shape” of your code and the words that are unique to your program.


F addNumbers {
    return 1 + 2 + 3;

T resultHtml(name) {
    <h1>> Hello {{ name }}!

[? error2 ?]

Quoted (Quick) Lists 

A list prefixed with Q will automatically convert the contents to a list of strings. The tokens are separated by whitespace (spaces or newlines).

let colors = Q[red blue yellow green];
// Same as ['red', 'blue', 'yellow', 'green']

// or separated by newlines
let colors = Q[


Ternary ? :

The ternary operator is a shortcut for 'if a, then b, else c'

// If/else form
if (condition) {
    a = r1;
} else {
    a = r2;

// Ternary form
a = condition ? r1 : r2;

// Examples
let a = true ? 'Yes' : 'No';   //= 'Yes'
let b = false ? 'Yes' : 'No';  //= 'No'

OR Assign ||=, AND Assign &&=

Logic and assignment can be combined into a single operator.

// OR assign.  Good for assigning a default value.
numGuests ||= 1;
// same as...
if (!numGuests) { numGuests = 1; }

// AND assign.  Good for processing a value further.
joinDate &&= formatDate(joinDate);
// same as...
if (joinDate) { joinDate = formatDate(joinDate); }

OR Value ||:, AND Value &&:

Rather than return true/false, logical value operators return the value on the left or right.

// OR value.  Good for a assigning a default value.
let b = 0;
let a = b || 2;   //= true  (2 is a truthy, or non-zero, value)
let a = b ||: 2;  //= 2     (the truthy value itself)

// same as...
if (!b) { a = 2; }

// AND value
b = 1;
a = b && 2;   //= true  (1 is truthy)
a = b &&: 2;  //= 0     (the falsey value itself)

Regular Expressions 

Some string methods take a regular expression (aka Regex) string as an argument.

Regex strings are prefixed with an uppercase 'R'. (e.g. R'[a-z]+').

Compared to normal strings, backslashes are treated literally and spaces are ignored (the regex 'x' flag is on by default).

See Regular Expression Syntax for more.

text.match(R'\w+ \s+ \w*');

// case insensitive match


When something goes wrong, it’s usually better to let the program die. A dead script can’t do any more damage, and is less likely to become a security vulnerability.

However, sometimes you want to provide a fallback for specific errors.

An Exception is an error that can be trapped with try/catch. The catch block will only run if there is an Exception in the try block.

let content = '';
try {
    // Will throw an Exception if it can't read the file.
    content ='important.txt');
} catch (e) {
    // Error reading the file.  Try to restore it and continue.
    content = getDefaultContent();
    File.write('important.txt', content);


A finally block can be used to define code that will run regardless of whether or not an Exception occurred.

This is optional, and is usually intended for cleanup logic that is invoked before the program ends.

try {
    // initial code
} catch (e) {
    // run if an Exception happens
} finally {
    // always run this after the above blocks complete

[? message2 ?]


You can trigger an Exception manually with die.

if (!fileExists) {
    die('Important file not found.');

To halt the program without triggering an Exception, use System.exit().