Skip to content

Basics and values

HollowScript programs are files of statements. There is no main function: the top level of a file is the program. A file can print, compute and return a value, but it can only reach the outside world through a capability it has been granted, such as print. Capabilities are covered properly in Effects and capabilities; for now, uses print at the top of a file is what lets it call print.

uses print
constant greeting = "hello"
variable count = 0
count = count + 1
count = count + 1
effect print("${greeting}, HollowScript ${count}")
effect print("${1 + 2 * 3} ${7 / 2} ${7.0 / 2.0}")
effect print("${true and false} ${true or false} ${not true}")

Output:

hello, HollowScript 2
7 3.5 3.5
false true false

A few things to notice:

  • constant binds a name once; variable binds a name that can be reassigned. Neither makes the value itself editable, values in HollowScript are always immutable, only a variable binding can point at a new one.
  • effect print(...) is a call, marked with effect because print is a capability function. The marker is required on every call that reaches a capability, and forbidden everywhere else. See section 9.3.
  • ${...} inside a string is interpolation: any expression of type Int, Float, Bool or String can be dropped straight into text. See section 3.9.
  • / always divides as Float, converting both operands first, even two Ints: 7 / 2 is the Float 3.5, the same as 7.0 / 2.0. Integer division and remainder are the library functions div, mod and remainder, not an operator. See section 3.4.
  • and, or and not are words, not symbols, and and/or short-circuit their right-hand side.

There is no null. An absent value is written none and only exists where an optional type is expected, that is the subject of the next page.