Object Oriented Programming

NEW CLASS defines a class — a named template of typed properties and methods. SPAWN creates an instance from a class. CALL ... ON invokes a method on an instance. EXTENDS inherits properties and methods from a parent class.

NEW CLASS

A class is declared with NEW CLASS followed by a bare name — no quotes, no SET. It registers the class by name, the same way NEW OPERATION registers an operation. Properties and methods are declared with WITH, chained by AND.

Defining a Class
NEW CLASS Person
WITH "name" AS STRING REQUIRED
AND "age" AS NUMBER DEFAULT 0
AND "email" AS STRING
AND "greet" AS METHOD
OPEN
  EMIT "Hello, I am " & "name" OF THIS
CLOSE

Property Modifiers

Modifier Meaning
AS STRING / AS NUMBER / AS BOOL / AS DATEProperty type
REQUIREDMust be supplied when the instance is spawned
DEFAULT valueFills automatically when omitted at spawn time
AS METHOD OPEN ... CLOSEAn executable block bound to the instance via THIS

SPAWN

SPAWN creates an instance of a class. Initial property values are supplied with WITH ... AND ..., matching the same chaining pattern used everywhere else. SET captures the resulting instance.

Spawning an Instance
NEW CLASS Person
WITH "name" AS STRING REQUIRED
AND "age" AS NUMBER DEFAULT 0
AND "email" AS STRING
AND "greet" AS METHOD
OPEN
  EMIT "Hello, I am " & "name" OF THIS
CLOSE
AFTER SPAWN Person
WITH "name" AS "Alice"
AND "age" AS 30
SET ?alice

Property Access

Instance properties are read and written exactly like any other object — no new syntax to learn.

Reading and Writing Properties
NEW CLASS Person
WITH "name" AS STRING REQUIRED
AND "age" AS NUMBER DEFAULT 0
AND "greet" AS METHOD
OPEN
  EMIT "Hello, I am " & "name" OF THIS
CLOSE
AFTER SPAWN Person
WITH "name" AS "Alice"
AND "age" AS 30
SET ?alice
AFTER EMIT ?alice("name")
AFTER EMIT "age" OF ?alice
AFTER SET ?alice("age") AS 31

CALL ... ON — Method Invocation

Methods are invoked with CALL "methodname" ON ?instance. The method body executes with THIS bound to the instance it was called on.

Calling a Method
NEW CLASS Person
WITH "name" AS STRING REQUIRED
AND "greet" AS METHOD
OPEN
  EMIT "Hello, I am " & "name" OF THIS
CLOSE
AFTER SPAWN Person
WITH "name" AS "Alice"
SET ?alice
AFTER CALL "greet" ON ?alice
(* Output: Hello, I am Alice *)

EXTENDS — Inheritance

A class inherits from another with EXTENDS. The child class gains all parent properties and methods. A child property or method with the same name overrides the parent's.

Inheriting from a Parent Class
NEW CLASS Person
WITH "name" AS STRING REQUIRED
AND "age" AS NUMBER DEFAULT 0
AND "greet" AS METHOD
OPEN
  EMIT "Hello, I am " & "name" OF THIS
CLOSE
AFTER NEW CLASS Employee
EXTENDS Person
WITH "department" AS STRING DEFAULT "general"
AND "work" AS METHOD
OPEN
  EMIT "name" OF THIS & " is working in " & "department" OF THIS
CLOSE
AFTER SPAWN Employee
WITH "name" AS "Bob"
AND "age" AS 28
AND "department" AS "Engineering"
SET ?bob
AFTER CALL "greet" ON ?bob
(* Output: Hello, I am Bob — inherited from Person *)
AFTER CALL "work" ON ?bob
(* Output: Bob is working in Engineering *)

Methods Change Their Instance

THIS is the instance itself, not a copy of it. A method that writes to THIS changes the object it was called on, and the change is there after the call returns. Both notations write, exactly as they both read.

A Method That Updates a Property
NEW CLASS Counter
WITH "n" AS NUMBER DEFAULT 0
AND "increment" AS METHOD
OPEN
  CALCULATE "n" OF THIS + 1 SET ?next
  AFTER SET "n" OF THIS AS ?next
CLOSE
AFTER SPAWN Counter SET ?c
AFTER CALL "increment" ON ?c
AFTER CALL "increment" ON ?c
AFTER EMIT ?c("n")
(* Emits: 2 *)

A method may also add a property the class never declared — an instance is an object, and objects grow.

What CALL Can Be Given

CALL ... ON accepts anything SET accepts as a target: a variable, an element, a key, a nested path, in either notation.

Calling a Method on a Nested Instance
NEW ARRAY SET ?counters
AFTER SPAWN Counter SET ?c
AFTER APPEND ?c TO ?counters
AFTER CALL "increment" ON ?counters(0)
AFTER EMIT ?counters(0)("n")
(* Emits: 1 — the element itself was updated *)

An instance that is not held anywhere — the result of an inline [SPAWN ...], for example — still runs its method, but there is nothing to write the change back into.

NEW CLASS registers a class definition by name, no SET. SPAWN creates an instance and captures it with SET. CALL ... ON invokes a method, binding THIS to the instance. EXTENDS inherits properties and methods from a parent class, with child definitions overriding matching parent names. THIS is the instance itself — a method that writes to it changes the object it was called on.