Keywords
How each of Program's keywords is rendered into Swift.
Contents
How a Program becomes Swift, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Swift 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 Swift it renders to.
- Naming considerations — how Program's dotted names are carried into Swift.
- Entry point — starting a program and mounting it as a SwiftUI app.
- Drivers — the native drivers that provide the interface, animation and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Swift behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Swift.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Swift keeps for itself, and how a colliding name is escaped.
Program keywords in Swift
Each of Program's keywords maps to idiomatic Swift. Names stay nested through caseless
enums (see the example); the reactive
keywords are calls into the runtime. Follow a keyword's own page for the full rendering and the
other targets.
| Keyword | Rendered Swift |
|---|---|
MODULE | A nested caseless enum — enum Ui { enum Button { enum Integer { … } } }. |
TYPE | A record becomes public struct Point { public let x: Double; public let y: Double; public init(_ x: Double, _ y: Double) { … } }; a union becomes public enum Shape { case circle(Circle); case rect(Rect) }. |
FUNCTION | public static func Name(…) -> ReactiveValue<T> { … return … }. |
NATIVE | A public static func whose body is the swift NATIVE string. |
INPUT | A parameter; a BINDING input is read and written. |
HOLE | A trailing closure parameter. |
LET | let name = …. |
STATE | let name = Reactive.State<T>(value). |
REVERSE | A write-back whose closing SET is Reactive.Set(state, value). |
WITH | Module.With(Name.self, Replacement.self) { … }. |
See JavaScript keywords for the per-keyword
detail and the modifiers; Swift differs in idiom (nested enums, struct/enum
types) but the mapping is the same.