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 let binding.
    • 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 a Result without (let _ = ...) emits a compiler warning.
    • Shorthand let forms ((let pat = expr), (let (values ...) = expr), and (let *dyn* = expr)) bind variables for all subsequent forms in the progn.
    • The final ⟨expr⟩ determines the value(s) and type of the progn (a single value, Void, or multiple values) and is in tail position when the progn is in tail position.
  • In top-level contexts (coalton-toplevel):
    • Splices zero or more top-level declarations, definitions, and attributes into the enclosing coalton-toplevel unit.
    • A top-level progn cannot be preceded by an attribute (repr, derive, inline, monomorphize, overlap) and cannot end with a trailing unconsumed attribute.

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