Example
The whole language in one short program — a module with a record, a tagged union, a function with per-platform native bodies, and a function that wires up state, a write-back and a return — and the complete Go it renders to. It is the same program shown on the language page.
Contents
How a Program becomes Go, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Go target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Go it renders to.
- Naming considerations — how Program's dotted names are carried into Go.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Go behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Go.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Go keeps for itself, and how a colliding name is escaped.
Every keyword, in one program
Each keyword has its own page under keywords; here they are all together.
MODULE App
TYPE Profile
FIELD Text name
FIELD Maths.Integer age
TYPE Status
OPTION App.Profile active
OPTION Text pending
FUNCTION Text Greet
INPUT Text name
NATIVE js "return 'Hi ' + name;"
NATIVE dart "return 'Hi ' + name;"
NATIVE go "return \"Hi \" + name"
FUNCTION Text Welcome
INPUT BINDING App.Profile profile
HOLE Text row
INPUT Text line
STATE Maths.Integer count = 0
STATE LOCKED Network.Web.Response saved = null
REVERSE App.Profile submit
LET Network.Web.Response response = Network.Web.Client.Post profile
SET saved = response
LET Text label = Maths.Integer.ToString count
= label
(The function's swift row is replaced with a go one here, since Go needs its
own NATIVE body.)
Rendered Go
The module is a package; the record and union are structs named by the underscore join; the
functions are methods on a zero-field “static” struct; state uses generics; the function's
go body is spliced in; and the trailing = becomes a return.
package app
type App_ProfileData struct {
name string
age int64
}
type App_StatusData struct {
tag string
active *App_ProfileData
pending *string
}
type AppStatic struct{}
var App = AppStatic{}
func (AppStatic) Greet(name string) string {
return "Hi " + name // the go NATIVE body
}
func (AppStatic) Welcome(profile *App_ProfileData, row func(line string) ReactiveValue[string]) ReactiveValue[string] {
count := Program._Runtime.Reactive.State[int64](0)
saved := Program._Runtime.Reactive.StateLocked[*Network_Web_Response](nil)
Program._Runtime.Reactive.Reverse(submit, func() {
response := Network_Web_Client.Post(profile)
Program._Runtime.Reactive.Set(saved, response) // SET
})
label := Maths_Integer.ToString(count)
return label
}
Reading it
Indentation becomes nested closures — the REVERSE
body is a func() { … }. Dotted names are joined with an underscore, keeping the final
access a real dot (Maths_Integer.ToString) — see
naming considerations. The per-keyword
mapping is on keywords.