The keyword ‘this’ acts as a synonym for the current variable or function where code is being executed. From the command prompt, this typically refers to the entire workspace. But when a function is running, ‘this’ refers to that function. For example:
f :: { int; this = args, return this }
and type f(5), our function will set its internal integer variable to 5 and return itself: { 5 }. In fact, this refers to the inside of any curly braces it appears in. For example, here:
myVar :: { a := 2, b := this[1] }
c will be set to 2.
The really tricky situation is inside the arguments of a function call, where this refers to the function arguments themselves. For reasons explained elsewhere, if we write
f(2, 5, this[2])
then we are effectively calling f(2, 5, 5). This means that, for example, we cannot print the number of workspace variables by typing
print(top(this)) | won't work
because that command will print ‘1’ which is the number of arguments passed to top(). What we really want to do is back out 2 levels, from the arguments of top() to the arguments of print() and then to the workspace, by typing
print(top(parent.parent))
parent is the second predefined keyword, and refers to the object in the search path just before this. A shorthand for parent is a backslash character, so the last example could also have been written
print(top(\.\))
A third keyword, which should appear only to the right of an assignment operator (= or <-), is called ‘that’, and it refers to whatever was on the left side of the assignment operator. It can be used to abbreviate cumbersome expressions such as
facts.num.N = facts.num.N * log(facts.num.N) + facts.num.N
with something like
facts.num.N = that * log(that) + that
The final keyword, called args, refers to a function’s arguments, which is usually a composite variable. Here’s a quick example:
I :: {
code
return { args, args[2] }
}
If we call I(1, 2, 3), our function I sends back { { 1, 2, 3 }, 2 }.
Last update: November 12, 2025