preludes / elm.lisp
elm
Elm-style applications. Messages, update, commands, and Hiccup views, checked against closed vocabularies and lowered to Foldkit.
Shared HttpApi client generation remains proposed. See the Elm prototype reference for current limits.
From the source
Purpose: Elm-style message, command, update, view, and application declarations. Requires: compiler.lisp; bootstrap separately from the ontology and HTTP API stacks. Used by: The optional TypeScript Elm linker and its Foldkit prototype examples.
Try it
Forms 5
Keywords this prelude adds. Each is a form descriptor: its slots, their types, and the IR it produces.
(msg variant ...)elm.lisp:23
Declares message variant syntax for the Elm linker, which builds the Msg tagged type.
| Slot | Type |
|---|---|
| variant | (List Syntax) |
Produces ElmMessagesIR
Example
(type Model {:count Int})
(msg Increment)
(update [model message]
Increment
(with (assoc model :count (+ model.count 1))))
(view [model] [:div (str model.count)])
(app Counter :model Model :init (with (Model {:count 0})))(command name operation {:keys [ok error]})elm.lisp:38
Declares a named command linked to an operation and success and optional error message syntax.
| Slot | Type |
|---|---|
| name | (Declares ElmCommand) |
| operation | Symbol |
| ok | Syntax |
| error | (Option Syntax) |
Produces ElmCommandIR · has a TypeScript :emit hook
Example
(type Model {:count Int})
(: read-count (Effect Int))
(define read-count 1)
(msg Load (Loaded {:count Int}))
(command load read-count :ok [n (Loaded {:count n})])
(update [model message]
Load
(with model :load)
(Loaded {:count n})
(with (assoc model :count n)))
(view [model] [:div (str model.count)])
(app Counter :model Model :init (with (Model {:count 0})))(update bindings case ...)elm.lisp:63
Captures model and message bindings and update cases for the Elm linker to typecheck and lower.
| Slot | Type |
|---|---|
| bindings | Syntax |
| case | (List Syntax) |
Produces ElmUpdateIR
Example
(type Model {:count Int})
(msg Increment)
(update [model message]
Increment
(with (assoc model :count (+ model.count 1))))
(view [model] [:div (str model.count)])
(app Counter :model Model :init (with (Model {:count 0})))(view bindings tree)elm.lisp:78
Captures model bindings and a Hiccup tree. The Elm linker checks element tags, attributes, and message handlers.
| Slot | Type |
|---|---|
| bindings | Syntax |
| tree | Syntax |
Produces ElmViewIR
Example
(type Model {:count Int})
(msg Increment)
(update [model message]
Increment
(with (assoc model :count (+ model.count 1))))
(view [model] [:div (str model.count)])
(app Counter :model Model :init (with (Model {:count 0})))(app name {:keys [model init]})elm.lisp:93
Declares an Elm application name, model type, and initial model expression; the linker combines its messages, update, view, and commands.
| Slot | Type |
|---|---|
| name | (Declares ElmApp) |
| model | Symbol |
| init | Syntax |
Produces ElmAppIR · has a TypeScript :emit hook
Example
(type Model {:count Int})
(msg Increment)
(update [model message]
Increment
(with (assoc model :count (+ model.count 1))))
(view [model] [:div (str model.count)])
(app Counter :model Model :init (with (Model {:count 0})))Types 8
Payload contracts and IR shapes, shown as authored.
ElmElementTagelm.lisp:9
The view linker accepts only these Hiccup element tags.
(type ElmElementTag (Union :div :span :button))ElmTextAttributeelm.lisp:11
Text-valued Hiccup attributes; keywords select HtmlBuilder methods.
(type ElmTextAttribute (Union :class))ElmMessageAttributeelm.lisp:13
Message-valued Hiccup event attributes checked by the Elm linker.
(type ElmMessageAttribute (Union :on-click))ElmMessagesIRelm.lisp:15
(type ElmMessagesIR {:kind "ElmMessages" :variants (List RuntimeExpr)})ElmCommandIRelm.lisp:16
(type ElmCommandIR
{:kind "ElmCommand" :name Symbol :operation Symbol
:ok RuntimeExpr :error (Option RuntimeExpr)})ElmUpdateIRelm.lisp:19
(type ElmUpdateIR {:kind "ElmUpdate" :bindings RuntimeExpr :cases (List RuntimeExpr)})ElmViewIRelm.lisp:20
(type ElmViewIR {:kind "ElmView" :bindings RuntimeExpr :tree RuntimeExpr})ElmAppIRelm.lisp:21
(type ElmAppIR {:kind "ElmApp" :name Symbol :model Symbol :init RuntimeExpr})