Syntax and values
KataScript files use the .ks extension. A program is a sequence of statements; semicolons are optional. Braces delimit function bodies and control-flow bodies.
# A line comment starts with a hash.let answer = 6 * 7print(answer)Whitespace and newlines do not define indentation-based scopes. Use indentation to make the brace structure easy to read.
Literal values
Section titled “Literal values”print(42) # Int: arbitrary precisionprint(3.5) # Float: 64-bit floating pointprint(0xff) # hexadecimal Intprint(0b1010) # binary Intprint(true)print(nil)print("hello")print(b'hello\xff') # Bin: bytesprint((1, "one")) # a tupleInt arithmetic is arbitrary precision. Float arithmetic is approximate. Integer division stays integer-valued: 5 / 2 evaluates to 2. Choose a floating-point operand when a fractional result is intended, and avoid using mixed numeric comparisons at extreme magnitudes as exact arithmetic.
You can inspect a value’s type:
print(typeof(42)) # Intprint(typeof("hello")) # Strprint(Int) # types themselves are valuesOperators
Section titled “Operators”| Purpose | Operators |
|---|---|
| Arithmetic | +, -, *, /, % |
| Comparison | ==, !=, <, >, <=, >= |
| Unary | -, ! |
| Short-circuit logic | &&, ` |
Multiplication, division, and remainder bind more tightly than addition and subtraction. Use parentheses when a grouping deserves emphasis. + also concatenates strings.
Logical operators evaluate their right-hand side only when needed. Falsy values include nil, false, numeric zero, the empty string, the empty tuple, and records with no fields. An empty array or map still has record fields and is truthy; test its length when you mean “has elements.”
Expressions that contain statements
Section titled “Expressions that contain statements”if and with can produce values from their final expression:
let label = if 8 > 5 { "large" } else { "small" }let area = with width = 6, height = 7 { width * height}print("{label}: {area}")with introduces a standalone scope, optionally with bindings. Bare braces do not introduce a standalone expression block. Map literal syntax is not implemented.
Next: bindings and scope.