Shortcuts
THT has shortcuts and other syntax that let you compress common patterns into more concise code.
Print >>
To make debugging with print statements easier to type, you can use the one-line >> shortcut instead.
>> $myVariable // is the same as... print($myVariable)
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).
// Same as ['red', 'blue', 'green']
$colors = q[red blue green]
// or separated by newlines
$colors = q[
red
blue
green
]
One-Liners
When you have a block containing a single statement, you can use a colon : to place it on the same line without curly braces.
if $a == 1: print('One!')
fun addOne($n): return $n + 1
foreach $colors as $c: print($c)
// Example nesting (try not to overdo it)
foreach $nums as $n: if $n < 10: print($n)
Self-Assignment
If you are assigning the value of a method call to the same variable, you can leave out the variable before the dot (.).
$str = .upperCase() // is the same as... $str = $str.upperCase()
Method calls can be chained as normal.
$str = .upperCase().reverse()