# Auxiliary Functions
The $\lambda$-notation in the Agda definitions of auxiliary functions for *Scm*
corresponds closely to that in its published denotational semantics [(Mosses2025CSE)].
```agda
{-# OPTIONS --rewriting --confluence-check --lossy-unification #-}
module Examples.Scm.Auxiliary-Functions where
open import Examples.Scm.Abstract-Syntax
open import Examples.Scm.Domain-Equations
import Notation
open Notation.Domains using (⟪_⟫; ⊥)
open Notation.Functions using (_→ᶜ_; fix)
open Notation.Flat using (↑)
open Notation.Flat.Booleans using (_⟶_,_; Eq; _==⊥_; true; false)
open Notation.Sums using (_in⊥_; _∈⊥_; _|⊥_)
open Notation.Products using (_,_; _↓₁; _↓₂)
open Notation.Products.Sequences using (⟨_⟩; #; _↓_; _†_)
open Notation.Updates using (_[_/_]⊥)
postulate instance
eqL : Eq Loc
eqM : Eq Misc
eqR : Eq Int
postulate
_<ᴿ_ : ⟪ 𝐑 →ᶜ 𝐑 →ᶜ 𝐓 ⟫
_+ᴿ_ : ⟪ 𝐑 →ᶜ 𝐑 →ᶜ 𝐑 ⟫
_∧ᵀ_ : ⟪ 𝐓 →ᶜ 𝐓 →ᶜ 𝐓 ⟫
postulate instance
eqIde : Eq Ide
postulate unknown : Loc
postulate initial-env : ⟪ 𝐔 ⟫
assign : ⟪ 𝐋 →ᶜ 𝐄 →ᶜ 𝐂 →ᶜ 𝐂 ⟫
assign α ϵ θ σ = θ (σ [ ϵ / α ]⊥)
hold : ⟪ 𝐋 →ᶜ (𝐄 →ᶜ 𝐂) →ᶜ 𝐂 ⟫
hold α κ σ = κ (σ α) σ
```
In the continuation-passing style used to define auxilary functions for *Scm*,
giving explicit continuity proofs would be particulary tedious.
For example, the function `hold` is simply a combination of
$\lambda$-abstraction and application, which is wellknown to ensure continuity.
```agda
postulate new : ⟪ (𝐋 →ᶜ 𝐂) →ᶜ 𝐂 ⟫
alloc : ⟪ 𝐄 →ᶜ (𝐋 →ᶜ 𝐂) →ᶜ 𝐂 ⟫
alloc ϵ κ = new (λ α → assign α ϵ (κ α))
postulate initial-store : ⟪ 𝐒 ⟫
postulate finished : ⟪ 𝐒 →ᶜ 𝐀 ⟫
```
Conventional denotational definitions usually leave the injection function `↑` from
sets into flat domains implicit, in contrast to the embedding of the definition of `truish`:
```agda
truish : ⟪ 𝐄 →ᶜ 𝐓 ⟫
truish ϵ = (ϵ ∈⊥ 𝐓) ⟶ (((ϵ |⊥ 𝐓) ==⊥ ↑ false) ⟶ ↑ false , ↑ true) ,
↑ true
```
The remaining auxiliary function definitions shown here involve the operations for (finite) sequences `ϵ⋆`
declared in the module `Notation.Products.Sequences`.
```agda
cons : ⟪ 𝐅 ⟫
cons ϵ⋆ κ = (# ϵ⋆ ==⊥ ↑ 2) ⟶
alloc (ϵ⋆ ↓ 1) (λ α₁ →
alloc (ϵ⋆ ↓ 2) (λ α₂ → κ ((α₁ , α₂) in⊥ 𝐄))) ,
⊥
```
In [(Mosses2025CSE)] the auxiliary function $\textit{list}$ is defined by recursion on `ϵ⋆`.
Agda accepts recursive definitions only when it can mechanically prove that the recursion terminates,
which is not the case for arguments in postulated types.
The following definition uses the postulated operation `fix` to avoid recursion.
```agda
list : ⟪ 𝐅 ⟫
list = fix λ (list′ : ⟪ 𝐅 ⟫) → λ ϵ⋆ κ →
(# ϵ⋆ ==⊥ ↑ 0) ⟶ κ (↑ null in⊥ 𝐄) ,
list′ (ϵ⋆ † 1) (λ ϵ → cons ⟨ (ϵ⋆ ↓ 1) , ϵ ⟩ κ)
car : ⟪ 𝐅 ⟫
car ϵ⋆ κ = (# ϵ⋆ ==⊥ ↑ 1) ⟶ hold (((ϵ⋆ ↓ 1) |⊥ 𝐏) ↓₁) κ , ⊥
cdr : ⟪ 𝐅 ⟫
cdr ϵ⋆ κ = (# ϵ⋆ ==⊥ ↑ 1) ⟶ hold (((ϵ⋆ ↓ 1) |⊥ 𝐏) ↓₂) κ , ⊥
setcar : ⟪ 𝐅 ⟫
setcar ϵ⋆ κ =
(# ϵ⋆ ==⊥ ↑ 2) ⟶
assign (((ϵ⋆ ↓ 1) |⊥ 𝐏) ↓₁) (ϵ⋆ ↓ 2) (κ (↑ unspecified in⊥ 𝐄)) ,
⊥
setcdr : ⟪ 𝐅 ⟫
setcdr ϵ⋆ κ =
(# ϵ⋆ ==⊥ ↑ 2) ⟶
assign (((ϵ⋆ ↓ 1) |⊥ 𝐏) ↓₂) (ϵ⋆ ↓ 2) (κ (↑ unspecified in⊥ 𝐄)) ,
⊥
```
[(MFPS2026-Agda)]: https://pdmosses.github.io/mfps2026-agda/
[(Mosses2025CSE)]: https://doi.org/10.1145/3759427.3760369
[Notation.Products.Sequences]: ../../Notation.md#Products.Sequences