progn sequences a series of expressions (and shorthand let bindings) in expression context, or splices a series of top-level forms in coalton-toplevel.
Syntax
;; Expression sequencing
(progn
⟨body-element⟩*
⟨expr⟩)
;; Top-level form splicing (inside `coalton-toplevel`)
(progn
⟨toplevel-form⟩*)
;; ⟨body-element⟩ := ⟨expr⟩
;; | (let ⟨pattern⟩ = ⟨expr⟩)
;; | (let (values ⟨var-or-_⟩*) = ⟨expr⟩)
;; | (let *⟨dynamic-var⟩* = ⟨expr⟩)
Semantics
- In expression contexts:
- Requires at least one expression and cannot end with a shorthand
letbinding. - Evaluates each
⟨body-element⟩sequentially from top to bottom. - Non-final expressions are evaluated for their side effects and their results (whether a single value,
Void, or multiple values) are discarded. Discarding aResultwithout(let _ = ...)emits a compiler warning. - Shorthand
letforms ((let pat = expr),(let (values ...) = expr), and(let *dyn* = expr)) bind variables for all subsequent forms in theprogn. - The final
⟨expr⟩determines the value(s) and type of theprogn(a single value,Void, or multiple values) and is in tail position when theprognis in tail position.
- Requires at least one expression and cannot end with a shorthand
- In top-level contexts (
coalton-toplevel):- Splices zero or more top-level declarations, definitions, and attributes into the enclosing
coalton-toplevelunit. - A top-level
progncannot be preceded by an attribute (repr,derive,inline,monomorphize,overlap) and cannot end with a trailing unconsumed attribute.
- Splices zero or more top-level declarations, definitions, and attributes into the enclosing
Examples
;; Expression-level `progn` with shorthand `let` bindings
(coalton
(progn
(let (Tuple x y) = (Tuple 3 4))
(let (values sum prod) = (values (+ x y) (* x y)))
(+ sum prod)))
; => 19
;; Splicing multiple top-level definitions in `coalton-toplevel`
(coalton-toplevel
(progn
(declare a Integer)
(define a 10)
(declare b Integer)
(define b (+ a 5))))
Other notes
- Implicit
prognbodies are used throughout Coalton indefine,fn,let,let*,when,unless,condclauses,match/catch/handle/resumablebranches,protectcleanup forms, andunsafe. An explicitprognis needed when grouping multiple expressions into a single-expression slot (such as a branch ofif) or when using shorthand(let x = ...)bindings insidecoalton.