An expression is a combination of one or more specific commands, queries, values or names that is computed sometimes with side-effects to produce a result value. Expressions are the smallest elements that describe an action in SkookumScript.
Performing the action and doing whatever computation is necessary is called code evaluation or often code execution. In SkookumScript, everything is an expression and all expressions return a result when evaluated.
Even nothing is a still a result
When an expression does not have an obvious result it returns
nil which is an object that essentially represents nothing or the absence of a value. This is a similar concept to a
void result in C++.
nil, or something like it, is common in many languages (Smalltalk, Lisp, Objective-C, Ruby). It goes by several different names, such as
nullptr (C++), and
Simple whitespace (which includes comments) is used to separate / delimit between expressions—or even no whitespace if the separation is obvious to the parser. Expressions do not need an end of expression / statement delimiter symbol (such as
. or newline)—the SkookumScript parser knows what is and is not a valid expression, and figures it out for you.
Same expressions with different spacing
println("expr1") println("expr2") println("expr3") println("expr1") println("expr2") println("expr3") println("expr1") println("expr2") println("expr3")
TIP Multiple expressions can be grouped together and treated as a single expression using a code block.
There several kinds of expressions:
- Literals create simple, handy building-block values such as numbers, strings of text, Booleans (
false), and lists, as well as more sophisticated objects known as closures (which represent a hunk of code as an object).
- Identifiers reference objects in the language and include variables, data members, and classes. Another form of identifier unique to SkookumScript is an object id, which references named objects often specified from outside the language (such as items placed in a game editor). Also related are the variable primitives for creating and setting variables.
- Invocations are the mechanisms for calling commands and actions called routines (methods and coroutines), which include special operator symbols for math, comparison and logic.
- Type Primitives includes expressions to manage type-checking and convert objects from one class type to another.
- Flow-control specifies expression groupings, alternate code paths, iterations for code to execute, timings and concurrency.