<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: clojure</title>
    <description>The latest articles tagged 'clojure' on DEV Community.</description>
    <link>https://dev.to/t/clojure</link>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tag/clojure"/>
    <language>en</language>
    <item>
      <title>Breaking the 2D Plane: OpenGL, Shaders, and the 3D Graphics Pipeline in Clojure &amp; Quil</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Sun, 15 Nov 2026 16:54:36 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/breaking-the-2d-plane-opengl-shaders-and-the-3d-graphics-pipeline-in-clojure-quil-3663</link>
      <guid>https://dev.to/ganesh_rajendran_art/breaking-the-2d-plane-opengl-shaders-and-the-3d-graphics-pipeline-in-clojure-quil-3663</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is **Part 3&lt;/em&gt;* of a 3-part series on &lt;strong&gt;The Invisible Brush: Generative Art &amp;amp; Creative Computation&lt;/strong&gt;:*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;Part 1: The Invisible Brush — Generative Art and the Algorithms That Paint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e"&gt;Part 2: Who Made This? The Author Shift and the Philosophy of Generative Art&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 3: Breaking the 2D Plane — OpenGL, Shaders, and the 3D Graphics Pipeline in Clojure &amp;amp; Quil&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;In &lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;Part 1&lt;/a&gt;, we explored procedural content generation by coding a scrolling 2D Perlin noise terrain cross-section. In &lt;a href="https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e"&gt;Part 2&lt;/a&gt;, we explored the philosophical author shift: the transition from executing individual marks to designing possibility spaces. Now, we pull back the canvas itself and examine what happens when mathematical functions meet raw silicon.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There is a comfortable lie at the center of creative coding tutorials. &lt;/p&gt;

&lt;p&gt;You write a function. You call &lt;code&gt;rect&lt;/code&gt;, &lt;code&gt;ellipse&lt;/code&gt;, or &lt;code&gt;line&lt;/code&gt;. A window appears, bathed in vibrant colors, and 60 times a second an organic universe unfurls across your monitor. We tell ourselves that code is paint, that functions are brushes, and that the canvas is an infinite, frictionless plane.&lt;/p&gt;

&lt;p&gt;Until you scale it.&lt;/p&gt;

&lt;p&gt;Add ten thousand animated particles. Increase your window resolution from 720p to 4K. Layer five octaves of noise across a dense spatial grid. Suddenly, the illusion shatters. The frame rate plummets from 60 to 12. The CPU fan spins up like a jet engine preparing for takeoff. Your garbage collector struggles to reclaim megabytes of short-lived heap allocations, and frame jitter turns your serene landscape into a stuttering slideshow.&lt;/p&gt;

&lt;p&gt;This is the &lt;strong&gt;CPU ceiling&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In Part 1, our terrain sketch ran comfortably on &lt;strong&gt;Java2D&lt;/strong&gt; — Processing’s default software renderer. Java2D is brilliant for learning: it requires zero GPU driver configuration, runs everywhere, and executes directly on the CPU. But it renders pixels by calculating geometry in host RAM and blitting rasterized scanlines into a software framebuffer byte array.&lt;/p&gt;

&lt;p&gt;To build living, immersive computational worlds, we must break out of the 2D plane. We must leave the comfort of CPU rasterization, bridge the JVM to native graphics drivers, and hand the heavy mathematical lifting to where it belongs: the massively parallel execution units of the GPU.&lt;/p&gt;

&lt;p&gt;In this article, we will deconstruct the full visual processing stack from Clojure down to the silicon. We will transform our 2D terrain slice into a full &lt;strong&gt;3D continuous landscape mesh&lt;/strong&gt;, navigate it with dynamic camera projections, illuminate it with calculated surface normals, and write custom &lt;strong&gt;GLSL hardware shaders&lt;/strong&gt; running directly on the GPU — all orchestrated through pure, functional Clojure.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Graphics Stack Deconstructed: From JVM to Silicon
&lt;/h2&gt;

&lt;p&gt;When you write Clojure code with &lt;a href="http://quil.info/" rel="noopener noreferrer"&gt;Quil&lt;/a&gt; (a Clojure wrapper around Processing’s &lt;code&gt;PApplet&lt;/code&gt;), what actually happens between your expression and the photons emitting from your monitor?&lt;/p&gt;

&lt;p&gt;The pipeline crosses four distinct architectural boundaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────┐
│ 1. Application Layer (Clojure / Quil)                       │
│    • Pure immutable simulation state (m/fun-mode)           │
│    • Functional geometry generation &amp;amp; noise evaluation      │
├─────────────────────────────────────────────────────────────┤
│ 2. Host Runtime (JVM / Processing PApplet)                  │
│    • State loop clock &amp;amp; event dispatch                      │
│    • Scene matrix stack (push-matrix, pop-matrix)           │
├─────────────────────────────────────────────────────────────┤
│ 3. API Abstraction Bridge (JOGL / JNI)                      │
│    • Java Native Interface bindings to desktop libGL        │
│    • Vertex Buffer Object (VBO) marshalling &amp;amp; draw calls    │
├─────────────────────────────────────────────────────────────┤
│ 4. Hardware Driver &amp;amp; GPU Silicon                            │
│    • Vertex Shader → Rasterizer → Fragment Shader           │
│    • Framebuffer depth test &amp;amp; blending → Monitor scanout    │
└─────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Rendering Paradigms: CPU vs. GPU
&lt;/h3&gt;

&lt;p&gt;To understand why 3D demands hardware acceleration, consider how rasterization works across both processors:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;CPU Software Rendering (&lt;code&gt;:java2d&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;GPU Hardware Pipeline (&lt;code&gt;:p3d&lt;/code&gt; / OpenGL)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Execution Architecture&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Few powerful, latency-optimized cores (4–16 threads)&lt;/td&gt;
&lt;td&gt;Thousands of high-throughput SIMD ALU cores&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Rasterization Mechanism&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Scans polygon edges in CPU cache; writes to JVM byte arrays&lt;/td&gt;
&lt;td&gt;Dedicated hardware rasterizer chips processing billions of fragments/sec&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory Bandwidth&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;DDR4/DDR5 system RAM (~40–80 GB/s)&lt;/td&gt;
&lt;td&gt;Dedicated GDDR6/HBM VRAM (~500–1,000+ GB/s)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Draw Call Overhead&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Low per-call cost; high per-pixel execution penalty&lt;/td&gt;
&lt;td&gt;High per-draw invocation cost; near-zero per-fragment cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Programmability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Standard JVM bytecode; CPU SIMD auto-vectorization&lt;/td&gt;
&lt;td&gt;Dedicated shader programs (GLSL / SPIR-V / WGSL)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Under &lt;code&gt;:java2d&lt;/code&gt;, drawing 100,000 shaded pixels requires the CPU to iterate through nested loops, calculate color values, and copy bytes to memory. The CPU’s branch predictors and deep instruction caches are completely wasted on this work.&lt;/p&gt;

&lt;p&gt;Under &lt;code&gt;:p3d&lt;/code&gt;, Quil switches its backend to &lt;strong&gt;JOGL&lt;/strong&gt; (Java OpenGL). Instead of coloring pixels in JVM memory, your Clojure code sends compact vertex arrays over the PCIe bus to GPU VRAM. The GPU’s rasterizer maps those vertices to screen tiles, while thousands of parallel fragment processors calculate colors and lighting in a single hardware cycle.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Breaking into the Third Dimension: Coordinate Systems &amp;amp; Matrices
&lt;/h2&gt;

&lt;p&gt;In 2D canvas drawing, the coordinate system is trivial: origin &lt;code&gt;(0, 0)&lt;/code&gt; sits at the top-left corner, &lt;code&gt;+X&lt;/code&gt; moves right, and &lt;code&gt;+Y&lt;/code&gt; moves down.&lt;/p&gt;

&lt;p&gt;In 3D, space is governed by linear algebra and homogeneous coordinates. When switching to &lt;code&gt;:p3d&lt;/code&gt;, Quil introduces the Z-axis and a 3-stage coordinate transformation pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Local Mesh Coordinates [X, Y, Z, 1.0]
              │
              ▼   (Model Matrix: position, rotation, scale)
World Space Coordinates
              │
              ▼   (View Matrix: camera eye, target, up-vector)
Camera / Eye Space Coordinates
              │
              ▼   (Projection Matrix: perspective field-of-view, near/far clipping)
Clip Space Coordinates (Homogeneous [-W..+W])
              │
              ▼   (Perspective Divide: divide by W)
Normalized Device Coordinates (NDC [-1.0..+1.0])
              │
              ▼   (Viewport Transform: map to window pixels)
Screen Framebuffer Coordinates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. The Model-View Transform (&lt;code&gt;q/camera&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;To position our viewpoint in the world, we configure the view matrix. Rather than manually translating and rotating every vertex, we define the camera using three 3D vectors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Eye position:&lt;/strong&gt; Where the observer stands in world space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target point:&lt;/strong&gt; The coordinate the camera is aimed at.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Up vector:&lt;/strong&gt; Which direction in the world represents "up" (typically &lt;code&gt;[0, 1, 0]&lt;/code&gt;).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;camera-position&lt;/span&gt;
  &lt;span class="s2"&gt;"Calculates camera eye coordinates from distance, orbit angle, and height."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;cam-distance&lt;/span&gt; &lt;span class="nv"&gt;cam-angle&lt;/span&gt; &lt;span class="nv"&gt;cam-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;cam-distance&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/sin&lt;/span&gt; &lt;span class="nv"&gt;cam-angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="nv"&gt;cam-height&lt;/span&gt;
   &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;cam-distance&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/cos&lt;/span&gt; &lt;span class="nv"&gt;cam-angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;setup-scene-camera&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:keys&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;cam-distance&lt;/span&gt; &lt;span class="nv"&gt;cam-angle&lt;/span&gt; &lt;span class="nv"&gt;cam-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;eye-x&lt;/span&gt; &lt;span class="nv"&gt;eye-y&lt;/span&gt; &lt;span class="nv"&gt;eye-z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;camera-position&lt;/span&gt; &lt;span class="nv"&gt;cam-distance&lt;/span&gt; &lt;span class="nv"&gt;cam-angle&lt;/span&gt; &lt;span class="nv"&gt;cam-height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="c1"&gt;;; (camera eye-x eye-y eye-z target-x target-y target-z up-x up-y up-z)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/camera&lt;/span&gt; &lt;span class="nv"&gt;eye-x&lt;/span&gt; &lt;span class="nv"&gt;eye-y&lt;/span&gt; &lt;span class="nv"&gt;eye-z&lt;/span&gt;
              &lt;span class="mf"&gt;0.0&lt;/span&gt; &lt;span class="mf"&gt;40.0&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;
              &lt;span class="mf"&gt;0.0&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;;; (perspective fov-radians aspect-ratio near-clip far-clip)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/perspective&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;Math/PI&lt;/span&gt; &lt;span class="mf"&gt;3.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                   &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                   &lt;span class="mf"&gt;10.0&lt;/span&gt;
                   &lt;span class="mf"&gt;3000.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Perspective vs. Orthographic
&lt;/h3&gt;

&lt;p&gt;By default, &lt;code&gt;:p3d&lt;/code&gt; applies &lt;strong&gt;perspective projection&lt;/strong&gt; via &lt;code&gt;(q/perspective fov aspect near far)&lt;/code&gt;. Objects farther from the camera diminish in size, creating depth cues and foreshortening. &lt;/p&gt;

&lt;p&gt;If you prefer architectural, isometric, or constructivist aesthetics where parallel lines never converge, Quil allows you to switch to &lt;strong&gt;orthographic projection&lt;/strong&gt; via &lt;code&gt;(q/ortho)&lt;/code&gt;. In an orthographic projection, a mountain ridge 2,000 units away retains the exact geometric scale as a pebble 50 units away.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Constructing the 3D Procedural Terrain
&lt;/h2&gt;

&lt;p&gt;In Part 1, our terrain was a one-dimensional height function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y = f(x, t)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate a true 3D topography, we expand the domain into a two-dimensional spatial continuous field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y = f(x, z, t)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every point &lt;code&gt;(x, z)&lt;/code&gt; on a discrete grid receives an elevation derived from layered 2D Perlin noise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multi-Frequency Octave Harmonics
&lt;/h3&gt;

&lt;p&gt;A raw Perlin noise query produces gentle, featureless swells. Real mountain geography exhibits fractal characteristics: large tectonic ridges modulated by medium hills, which are in turn carved by fine, rugged boulders.&lt;/p&gt;

&lt;p&gt;We synthesize this by summing noise across multiple &lt;strong&gt;octaves&lt;/strong&gt;, doubling the frequency and halving the amplitude at each step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;height-at&lt;/span&gt;
  &lt;span class="s2"&gt;"Calculates terrain elevation at grid coordinate (x, z) at time t.
   Uses multi-frequency octave Perlin noise to combine broad rolling contours
   with high-frequency surface roughness."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;octave-sum&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;reduce&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;freq&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                            &lt;span class="nv"&gt;amp&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;amp&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="mf"&gt;0.0&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;range&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;;; Normalization factor for sum of geometric progression 1/2^i&lt;/span&gt;
        &lt;span class="nv"&gt;norm&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dec&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;octave-sum&lt;/span&gt; &lt;span class="nv"&gt;norm&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the normalization factor &lt;code&gt;norm&lt;/code&gt;. Because each octave adds an amplitude of &lt;code&gt;1 / 2^i&lt;/code&gt;, the theoretical sum approaches &lt;code&gt;2.0&lt;/code&gt;. Normalizing guarantees our elevation output remains strictly bounded in &lt;code&gt;[0.0, elevation-scale]&lt;/code&gt;, ensuring mathematical safety and preventing clipping artifacts.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Mesh Topology: The Power of Triangle Strips
&lt;/h2&gt;

&lt;p&gt;How should we send this grid of (X, Z) points to the GPU?&lt;/p&gt;

&lt;p&gt;If you draw individual independent triangles with &lt;code&gt;(q/begin-shape :triangles)&lt;/code&gt;, a grid of 50 × 50 cells requires:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50 × 50 × 2 = 5,000 triangles × 3 vertices = 15,000 vertex calls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every interior vertex is specified and transformed up to 6 times.&lt;/p&gt;

&lt;p&gt;Instead, we use &lt;strong&gt;Triangle Strips&lt;/strong&gt; (&lt;code&gt;:triangle-strip&lt;/code&gt;). In a triangle strip, every vertex after the first two creates a new triangle sharing the previous edge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row Z:   v0 ───── v2 ───── v4 ───── v6
         │ ╲      │ ╲      │ ╲      │
         │   ╲    │   ╲    │   ╲    │
Row Z+1: v1 ───── v3 ───── v5 ───── v7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each row of our grid becomes a single continuous strip. To render 50 rows of 50 columns, we submit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50 strips × (50 × 2) = 5,000 vertex calls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We eliminate 66% of vertex memory traffic over the bus with zero visual loss.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deriving Surface Normals via Finite Differences
&lt;/h3&gt;

&lt;p&gt;Without lighting, a 3D terrain looks like a flat, silhouette polygon. To interact with light, the GPU requires a &lt;strong&gt;normal vector&lt;/strong&gt; &lt;code&gt;n = (nx, ny, nz)&lt;/code&gt; at every vertex — a unit vector perpendicular to the surface.&lt;/p&gt;

&lt;p&gt;Because our terrain is defined by a mathematical heightfield function, we do not need to pre-bake geometry. We can calculate the exact surface gradient analytically on the fly using &lt;strong&gt;finite differences&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;surface-normal&lt;/span&gt;
  &lt;span class="s2"&gt;"Calculates the unit surface normal vector [nx ny nz] at grid (x, z)
   using finite-difference height gradients along X and Z."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt; &lt;span class="nv"&gt;cell-size&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;hl&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;height-at&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dec&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;hr&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;height-at&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;inc&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;hu&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;height-at&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dec&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;hd&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;height-at&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;inc&lt;/span&gt; &lt;span class="nv"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt; &lt;span class="nv"&gt;roughness&lt;/span&gt; &lt;span class="nv"&gt;elevation-scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;dx&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;hr&lt;/span&gt; &lt;span class="nv"&gt;hl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;dz&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;hd&lt;/span&gt; &lt;span class="nv"&gt;hu&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;dy&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="nv"&gt;cell-size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;;; Vector (-dx, dy, -dz) pointing outward and upward&lt;/span&gt;
        &lt;span class="nv"&gt;nx&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;ny&lt;/span&gt; &lt;span class="nv"&gt;dy&lt;/span&gt;
        &lt;span class="nv"&gt;nz&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;dz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;len&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/sqrt&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;nx&lt;/span&gt; &lt;span class="nv"&gt;nx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;ny&lt;/span&gt; &lt;span class="nv"&gt;ny&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;nz&lt;/span&gt; &lt;span class="nv"&gt;nz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;zero?&lt;/span&gt; &lt;span class="nv"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;nx&lt;/span&gt; &lt;span class="nv"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;ny&lt;/span&gt; &lt;span class="nv"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;nz&lt;/span&gt; &lt;span class="nv"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When directional sunlight strikes the surface, the dot product between the sun vector &lt;code&gt;L&lt;/code&gt; and our normal &lt;code&gt;n&lt;/code&gt; creates realistic diffuse shading: slopes facing the light brighten, while backfaces fall into shadow.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Hardware Shaders: Injecting GLSL into the JVM
&lt;/h2&gt;

&lt;p&gt;Processing’s built-in lighting (&lt;code&gt;q/lights&lt;/code&gt;, &lt;code&gt;q/directional-light&lt;/code&gt;) is convenient, but it binds you to fixed-function shading models. What if you want non-linear atmospheric depth, distance fog, or iridescent terrain coloring?&lt;/p&gt;

&lt;p&gt;You write custom &lt;strong&gt;GLSL (OpenGL Shading Language)&lt;/strong&gt; programs.&lt;/p&gt;

&lt;p&gt;In Quil &lt;code&gt;:p3d&lt;/code&gt;, a shader is split into two stages compiled and executed entirely on the GPU:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clojure / Host Memory
   │
   ├── Attributes:  position, normal, color (per vertex)
   ├── Uniforms:    transform matrices, u_time, fog_color (global)
   │
   ▼
[Vertex Shader: terrain.vert]
   └── Transforms vertex positions from world space to clip space
   └── Interpolates normals and colors across triangle faces
         │
         ▼
[Hardware Rasterizer]
   └── Discretizes triangles into fragments (candidate pixels)
         │
         ▼
[Fragment Shader: terrain.frag]
   └── Runs for every visible pixel simultaneously
   └── Computes depth attenuation, sunlight diffusion, and atmospheric fog
         │
         ▼
[Framebuffer / Screen]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Vertex Shader (&lt;code&gt;terrain.vert&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight glsl"&gt;&lt;code&gt;&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;mat4&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;mat4&lt;/span&gt; &lt;span class="n"&gt;modelview&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;mat4&lt;/span&gt; &lt;span class="n"&gt;projection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;mat3&lt;/span&gt; &lt;span class="n"&gt;normalMatrix&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;attribute&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;attribute&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;attribute&lt;/span&gt; &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;vertColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;vertNormal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;vertPosition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;gl_Position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;vertColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;vertNormal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalMatrix&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;vertPosition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Processing automatically binds its active transformation matrices (&lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;normalMatrix&lt;/code&gt;) and per-vertex attributes (&lt;code&gt;position&lt;/code&gt;, &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;normal&lt;/code&gt;). The vertex shader simply projects the vertex into screen clip space and passes the interpolated varyings to the fragment stage.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fragment Shader (&lt;code&gt;terrain.frag&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight glsl"&gt;&lt;code&gt;&lt;span class="cp"&gt;#ifdef GL_ES&lt;/span&gt;
&lt;span class="n"&gt;precision&lt;/span&gt; &lt;span class="n"&gt;mediump&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;precision&lt;/span&gt; &lt;span class="n"&gt;mediump&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;#endif&lt;/span&gt;

&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;u_time&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;fog_color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;fog_near&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;fog_far&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;vertColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;vertNormal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;varying&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;vertPosition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. Perspective depth calculation&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gl_FragCoord&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;gl_FragCoord&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;fog_factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;smoothstep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fog_near&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fog_far&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// 2. Directional sunlight diffuse shading&lt;/span&gt;
    &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;light_dir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;vec3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vertNormal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;light_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;lit_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vertColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.35&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.65&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// 3. Blend lit surface into atmospheric horizon fog&lt;/span&gt;
    &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;final_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lit_color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fog_color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fog_factor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;gl_FragColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;vec4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;final_color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vertColor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Feeding Clojure Data into GPU Uniforms
&lt;/h3&gt;

&lt;p&gt;In Clojure, we compile the shader during &lt;code&gt;setup&lt;/code&gt; and update its uniforms dynamically in each frame of &lt;code&gt;draw-state&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;draw-state&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/background&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;setup-scene-camera&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:shader&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;and&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:use-shader?&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/shader&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;;; Update GLSL uniforms on the GPU&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.set&lt;/span&gt; &lt;span class="nv"&gt;^processing.opengl.PShader&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"u_time"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.set&lt;/span&gt; &lt;span class="nv"&gt;^processing.opengl.PShader&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"fog_color"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="mf"&gt;0.086&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="mf"&gt;0.102&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="mf"&gt;0.149&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.set&lt;/span&gt; &lt;span class="nv"&gt;^processing.opengl.PShader&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"fog_near"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="mf"&gt;500.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.set&lt;/span&gt; &lt;span class="nv"&gt;^processing.opengl.PShader&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="s2"&gt;"fog_far"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;float&lt;/span&gt; &lt;span class="mf"&gt;1600.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;setup-lighting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;draw-terrain-mesh&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;and&lt;/span&gt; &lt;span class="nv"&gt;sh&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:use-shader?&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/reset-shader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By pushing atmospheric fog calculation to &lt;code&gt;terrain.frag&lt;/code&gt;, the GPU calculates smooth, distance-attenuated atmospheric haze for hundreds of thousands of fragments with zero CPU cycle penalty.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. The Pure Functional GPU Loop (&lt;code&gt;m/fun-mode&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;There is an inherent philosophical tension when coupling Clojure with OpenGL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clojure's world:&lt;/strong&gt; Immutable values, pure functions, persistent data structures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenGL's world:&lt;/strong&gt; A mutable global state machine with framebuffers, bound contexts, and side-effecting draw calls.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How does Quil bridge this divide without corrupting functional purity?&lt;/p&gt;

&lt;p&gt;Through the &lt;strong&gt;&lt;code&gt;m/fun-mode&lt;/code&gt;&lt;/strong&gt; middleware.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;fun-mode&lt;/code&gt;, the sketch lifecycle is divided into two strictly isolated phases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────┐
│ Pure Functional Domain (No Side Effects)                    │
│                                                             │
│   state_0 ──► (update-state state_0) ──► state_1 ──► ...    │
│   (pure immutable Clojure maps: time, camera angles)       │
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼  (passed as read-only snapshot)
┌─────────────────────────────────────────────────────────────┐
│ Imperative Hardware Domain (Side Effects Confined)          │
│                                                             │
│   (draw-state state_n)                                      │
│   └── Sets camera uniforms                                  │
│   └── Binds GLSL PShader                                    │
│   └── Submits triangle strip vertex streams to OpenGL VBO   │
└─────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because &lt;code&gt;update-state&lt;/code&gt; is a pure function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;update-state&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:fly-speed&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:cam-angle&lt;/span&gt; &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.003&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our entire generative simulation — camera trajectory, flight velocity, spatial noise evolution — can be tested, stepped, or replayed in a headless REPL without ever opening an X11 window or touching an OpenGL context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;deftest&lt;/span&gt; &lt;span class="nv"&gt;update-state-test&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;testing&lt;/span&gt; &lt;span class="s2"&gt;"Update state increments flight time and camera orbit angle"&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;s0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;t3d/initial-state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="nv"&gt;s1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;t3d/update-state&lt;/span&gt; &lt;span class="nv"&gt;s0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;s0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:cam-angle&lt;/span&gt; &lt;span class="nv"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:cam-angle&lt;/span&gt; &lt;span class="nv"&gt;s0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The messy, stateful reality of OpenGL is confined entirely to the leaf boundary of &lt;code&gt;draw-state&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Architectural Comparison: Where Does Your Code Live?
&lt;/h2&gt;

&lt;p&gt;As your generative art expands from interactive experiments to large-scale gallery installations, choosing the correct layer in the processing stack becomes an engineering decision:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Architecture&lt;/th&gt;
&lt;th&gt;Pipeline Core&lt;/th&gt;
&lt;th&gt;Latency / FPS&lt;/th&gt;
&lt;th&gt;Max Complexity&lt;/th&gt;
&lt;th&gt;Best Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Quil :java2d&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;CPU (Java2D rasterizer)&lt;/td&gt;
&lt;td&gt;60 FPS up to ~5k elements&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;2D vector art, book typography, pen plotter SVG exports&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Quil :p3d (OpenGL)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;GPU (JOGL / Desktop OpenGL)&lt;/td&gt;
&lt;td&gt;60 FPS up to ~500k vertices&lt;/td&gt;
&lt;td&gt;Medium-High&lt;/td&gt;
&lt;td&gt;Live desktop visuals, audiovisual REPL sets, 3D generative terrains&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Browser (p5.js / Three.js)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;GPU (WebGL 2 / WebGPU)&lt;/td&gt;
&lt;td&gt;60 FPS up to ~2M instances&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Instant URL sharing, web installations, on-chain generative tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Native Compute (Vulkan / WGSL)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;GPU Compute Shaders&lt;/td&gt;
&lt;td&gt;120 FPS up to 10M+ particles&lt;/td&gt;
&lt;td&gt;Extreme&lt;/td&gt;
&lt;td&gt;Real-time Navier-Stokes fluid grids, Physarum slime mold swarms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  8. Running the Complete 3D Engine
&lt;/h2&gt;

&lt;p&gt;To assemble and run the complete 3D engine, organize the project with a standard Clojure CLI layout:&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Layout
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terrain-3d/
├── deps.edn                     # Clojure CLI configuration &amp;amp; Quil dependency
├── resources/
│   └── shaders/
│       ├── terrain.vert         # Vertex projection shader
│       └── terrain.frag         # Fragment shader (depth fog &amp;amp; directional lighting)
├── src/
│   └── generative/
│       └── terrain_3d.clj       # 3D terrain generator, camera math &amp;amp; Quil P3D sketch
├── test/
│   └── generative/
│       ├── terrain_3d_test.clj  # Headless test suite (math, normal vectors, state)
│       └── test_runner.clj      # Test runner
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dependency Configuration (&lt;code&gt;deps.edn&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:paths&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src"&lt;/span&gt; &lt;span class="s2"&gt;"resources"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
 &lt;span class="ss"&gt;:deps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;quil/quil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:mvn/version&lt;/span&gt; &lt;span class="s2"&gt;"4.3.1563"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="ss"&gt;:aliases&lt;/span&gt;
 &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:run&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:main-opts&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-m"&lt;/span&gt; &lt;span class="s2"&gt;"generative.terrain-3d"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="ss"&gt;:test&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:extra-paths&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
         &lt;span class="ss"&gt;:main-opts&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-m"&lt;/span&gt; &lt;span class="s2"&gt;"generative.test-runner"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running the Test Suite (Headless)
&lt;/h3&gt;

&lt;p&gt;Because the mathematical models and normal derivations are pure functions, you can verify the entire simulation pipeline without an active display server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure -M:test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Testing generative.terrain-3d-test

Ran 6 tests containing 134 assertions.
0 failures, 0 errors.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Launching the Interactive 3D Window
&lt;/h3&gt;

&lt;p&gt;If you are running in a desktop environment with an active display server (&lt;code&gt;X11&lt;/code&gt; or &lt;code&gt;Wayland&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Launch interactive 3D terrain flight&lt;/span&gt;
clojure -M:run

&lt;span class="c"&gt;# Launch in wireframe inspection mode&lt;/span&gt;
clojure -M:run --wireframe

&lt;span class="c"&gt;# Render a single high-resolution snapshot frame to disk&lt;/span&gt;
clojure -M:run --snapshot terrain_3d.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Closing the Loop: The Three Layers of Creative Coding
&lt;/h2&gt;

&lt;p&gt;Over the course of &lt;em&gt;The Invisible Brush&lt;/em&gt; series, we have traveled across three complementary perspectives on generative computation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 (The Technique):&lt;/strong&gt; How algorithms act as paintbrushes — using Perlin noise, grammars, and cellular automata to compute content on demand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2 (The Philosophy):&lt;/strong&gt; The upstream author shift — recognizing that the generative artist designs possibility spaces and tunes the spectrum of control between rigid order and static chaos.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 3 (The Silicon):&lt;/strong&gt; The mechanical substrate — lifting the canvas into the third dimension, understanding graphics memory bandwidth, and pairing Clojure’s functional purity with the raw parallel power of the GPU.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Code is not paint, and monitors are not canvases. But when functional abstractions and hardware architectures align, algorithms become something far more powerful: an engine of endless, structured surprise.&lt;/p&gt;




&lt;h3&gt;
  
  
  References &amp;amp; Further Reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://processing.org" rel="noopener noreferrer"&gt;Processing Foundation Documentation&lt;/a&gt; — Official API specifications for &lt;code&gt;PApplet&lt;/code&gt; and &lt;code&gt;PShader&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://quil.info/" rel="noopener noreferrer"&gt;Quil API Documentation&lt;/a&gt; — Functional Clojure wrappers for Processing and JOGL.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.khronos.org/opengl/" rel="noopener noreferrer"&gt;OpenGL Specification &amp;amp; GLSL Reference&lt;/a&gt; — The Khronos Group.&lt;/li&gt;
&lt;li&gt;Inigo Quilez — &lt;a href="https://iquilezles.org" rel="noopener noreferrer"&gt;Articles on Shaders, SDFs, and Distance Fog&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Real-Time Rendering, 4th Edition — Tomas Akenine-Möller, Eric Haines, Naty Hoffman.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>creativecoding</category>
      <category>opengl</category>
      <category>shaders</category>
    </item>
    <item>
      <title>Who Made This? The Author Shift and the Philosophy of Generative Art</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Sun, 15 Nov 2026 13:32:49 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e</link>
      <guid>https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is **Part 2&lt;/em&gt;* of a 3-part series on &lt;strong&gt;The Invisible Brush: Generative Art &amp;amp; Creative Computation&lt;/strong&gt;:*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;Part 1: The Invisible Brush — Generative Art and the Algorithms That Paint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2: Who Made This? The Author Shift and the Philosophy of Generative Art&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/breaking-the-2d-plane-opengl-shaders-and-the-3d-graphics-pipeline-in-clojure-quil-3663"&gt;Part 3: Breaking the 2D Plane — OpenGL, Shaders, and the 3D Graphics Pipeline in Clojure &amp;amp; Quil&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;In the &lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;previous post&lt;/a&gt; we built a Perlin noise terrain sketch in Clojure and Quil — a landscape that scrolls forever without ever being drawn. Now let us ask what that act means.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There is a moment every generative artist knows. The sketch compiles. The window opens. And the first thing you feel is not satisfaction — it is surprise. Something appears on screen that you did not plan, did not foresee, and could not have drawn by hand if you tried. You wrote the system. The system made the thing. And yet it is undeniably &lt;em&gt;yours&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This dissonance is not a bug. It is the whole point.&lt;/p&gt;

&lt;p&gt;Generative art has existed since the 1960s — before personal computers, before the internet, long before NFTs turned it into a cultural flashpoint. But its central philosophical question is older than computers entirely. It is the oldest question in art: &lt;em&gt;what counts as making?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Computers just asked it again, with new sharpness.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Author Shift
&lt;/h2&gt;

&lt;p&gt;Traditional art has a simple topology:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Artist → Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The painter's hand moves. The mark appears. The relationship is direct, legible, and unambiguous. The Sistine Chapel's ceiling exists because Michelangelo lay on a scaffold and moved a brush across wet plaster, section by section, for four years.&lt;/p&gt;

&lt;p&gt;Generative art breaks this. Its topology is different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Artist → System → Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The artist's creative act moves &lt;strong&gt;upstream&lt;/strong&gt;. It is no longer applied to the output — it is applied to the &lt;em&gt;rules that produce&lt;/em&gt; the output. The output itself emerges from those rules, often in ways the artist could not predict and did not intend.&lt;/p&gt;

&lt;p&gt;This upstream shift is what I mean by the &lt;strong&gt;author shift&lt;/strong&gt;. The locus of authorship relocates from execution to design. From mark to mechanism. The artist becomes, in a precise sense, a &lt;em&gt;designer of possibility spaces&lt;/em&gt; rather than a maker of things.&lt;/p&gt;

&lt;p&gt;Vera Molnár understood this in 1968. Working at the Sorbonne with access to a mainframe and a plotter, she began writing programs that produced geometric compositions — grids of squares, each one slightly perturbed, each one slightly wrong in its own way. She was not drawing the squares. She was writing the rules that drew them. The imperfections were hers; the specific imperfection of any given square was not.&lt;/p&gt;

&lt;p&gt;She called this work a form of controlled disorder. She was precise about it. She was not interested in randomness for its own sake. She was interested in the &lt;em&gt;calibration&lt;/em&gt; of randomness — in finding the amount of deviation from regularity that felt alive rather than mechanical.&lt;/p&gt;

&lt;p&gt;She was, without the vocabulary, describing the spectrum of control.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Spectrum
&lt;/h2&gt;

&lt;p&gt;Here is the central concept. Everything else hangs off it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Full Chaos ←————————————————————————→ Full Control
  white noise         flow fields        LOGO turtle
  (not art)            Fidenza            (rigid)
                           ↑
                  sweet spot: structured surprise
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the far left: pure randomness. Every pixel an independent coin flip. This is not art — it is static. There is no structure to find meaning in, no pattern for the eye to follow. The surprise has no grammar.&lt;/p&gt;

&lt;p&gt;At the far right: total control. Every mark specified. Every position determined. This is not generative — it is drafting. It may be beautiful, but it is not emergent. The artist is not discovering; they are executing.&lt;/p&gt;

&lt;p&gt;The sweet spot lives between them. Enough randomness that no two outputs are identical, that the system can surprise you. Enough structure that the outputs share a recognisable DNA, that you can look at a hundred pieces from the same system and know immediately that they came from the same mind.&lt;/p&gt;

&lt;p&gt;The craft of generative art is &lt;strong&gt;tuning this dial&lt;/strong&gt;. Not finding the dial's correct setting — there is no universal correct setting — but developing the judgment to know when a given system is too wild, too rigid, or just alive enough.&lt;/p&gt;

&lt;p&gt;This is not a metaphor. It is a literal engineering problem. When you write a generative system, every parameter is a physical position on this spectrum. Turn one number up and you slide toward chaos. Turn another down and you slide toward rigidity. The composition of your parameters is the composition of your aesthetic.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Terrain Sketch, Reframed
&lt;/h2&gt;

&lt;p&gt;In the previous post, we built this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;terrain-height&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;noise-val&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mf"&gt;0.008&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;base&lt;/span&gt;      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;amplitude&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;base&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;noise-val&lt;/span&gt; &lt;span class="nv"&gt;amplitude&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We examined the parameters then as knobs to turn. Let us look at them again — not as engineering values, but as &lt;em&gt;aesthetic positions on the spectrum&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;0.008&lt;/code&gt; multiplier on &lt;code&gt;x&lt;/code&gt; is the &lt;strong&gt;spatial frequency&lt;/strong&gt; of your chaos. It determines how rapidly the noise function varies as you move across the canvas. A small number means the noise changes slowly — wide, rolling hills, the terrain of a meadow. A large number means it changes fast — jagged, fractured peaks, the terrain of a nightmare.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Toward control: smooth, slow variation&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mf"&gt;0.002&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;; →  gently rolling plains&lt;/span&gt;

&lt;span class="c1"&gt;;; Toward chaos: rapid, frenetic variation&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;; →  shattered, spiky ridgeline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither extreme is interesting for long. The plains feel like a screensaver. The spikes feel like noise. The original &lt;code&gt;0.008&lt;/code&gt; sits at a particular aesthetic conviction: hills that have &lt;em&gt;character&lt;/em&gt;, that could be named, that feel like they might have rivers on the other side.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;amplitude&lt;/code&gt; — currently &lt;code&gt;(* canvas-height 0.5)&lt;/code&gt; — is the &lt;strong&gt;vertical range of your chaos&lt;/strong&gt;. At zero, the terrain is a flat line: pure control, no variance, dead. At full canvas height, the terrain oscillates between the top and the bottom of the frame on every column: pure chaos, violent, unreadable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Toward control: shallow variation, terrain barely breathes&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;amplitude&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nv"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Toward chaos: extreme variation, terrain thrashes&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;amplitude&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nv"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the time step — &lt;code&gt;0.005&lt;/code&gt; added to &lt;code&gt;t&lt;/code&gt; each frame — is the &lt;strong&gt;temporal pace of change&lt;/strong&gt;. This one is philosophically interesting because it is not about the still image at all. It is about the &lt;em&gt;experience of watching&lt;/em&gt;. A very small time step produces a system that evolves almost imperceptibly — geological time, the feeling of standing on a hillside and watching it very slowly become a different hillside. A large time step produces something that feels unstable, urgent, anxious.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Toward stillness (control): barely breathing&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.0005&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Toward turbulence (chaos): rapid, restless churn&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of these parameters is a &lt;em&gt;stance&lt;/em&gt;. A claim about what this landscape should feel like. The generative artist does not choose the specific hillside — they choose the &lt;em&gt;kind of hillside that is possible&lt;/em&gt;. And that choice is entirely authorial.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sixty Years of Tuning the Dial
&lt;/h2&gt;

&lt;p&gt;Generative art has a history. It is not a recent phenomenon invented by blockchain platforms, and it is not the product of machine learning. It is a lineage of artists who, starting in the 1960s, began asking what it would mean to write systems that made things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vera Molnár and Manfred Mohr&lt;/strong&gt; (1960s–70s) were among the first. Working with plotters — physical machines that dragged pens across paper under program control — they produced work that was rigorous, geometric, and undeniably art. Mohr's early work decomposed the hypercube into its constituent lines and edges, then systematically varied which lines were visible. The system was his; the specific variation on any given print was the algorithm's. He was comfortable with this. He said the computer was not replacing him — it was &lt;em&gt;extending&lt;/em&gt; him, letting him explore a space of possibilities that no human hand could traverse in a lifetime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Harold Cohen&lt;/strong&gt; (1970s–90s) went further. He built AARON — an AI system (rule-based, not neural) that could draw. Not follow pre-specified paths, but &lt;em&gt;draw&lt;/em&gt;: make decisions about composition, figure placement, mark-making. Cohen spent decades refining AARON's rules, adding capabilities, arguing about whether AARON was an artist or a tool. He never fully resolved it. He continued refining the rules until he died in 2016.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Karl Sims&lt;/strong&gt; (1980s–90s) introduced evolution. His systems bred virtual creatures — 3D bodies with neural controllers — selecting for locomotion. The creatures that moved better survived; the ones that did not, did not. What emerged were organisms with gaits that looked like nothing in nature, because they had evolved under different physics. Sims did not design the creatures. He designed the selection pressure. The specific morphology of any given creature was the product of thousands of simulated generations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Casey Reas and Ben Fry&lt;/strong&gt; (2000s) democratised the whole field. Processing — the open-source environment they created — put generative tools in the hands of designers and artists who were not programmers. The community that grew up around it is the direct ancestor of creative coding today. Reas in particular wrote extensively about software as a medium with its own aesthetic concerns, its own history, its own standards of craft.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Robert Hodgin and Anders Hoff&lt;/strong&gt; (2010s) represent the creative coding era at its most refined. Hodgin — known online as &lt;em&gt;flight404&lt;/em&gt; — built systems of extraordinary physical beauty: fluid simulations, starfield renderers, typographic forms shaped by gravity. His work demonstrated that generative code could meet the visual standards of commercial motion design without sacrificing any of its procedural character. Hoff, working under the name &lt;em&gt;inconvergent&lt;/em&gt;, pursued a different register: fine-art prints where the generative process was explicit in the form — lines that accumulated, that crowded, that reacted to their own density. His work looked like it was drawn by a patient hand, because in a sense it was: the hand was the algorithm, running for hours, making thousands of small decisions the artist had authored once and released.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tyler Hobbs and Dmitri Cherniak&lt;/strong&gt; (2020s) brought generative art to a new audience through on-chain distribution — Art Blocks, long-form generative collections where every token is a unique output from a single algorithm, stored permanently on the Ethereum blockchain. Hobbs's &lt;em&gt;Fidenza&lt;/em&gt; is widely considered the canonical example of a generative system tuned to a genuinely refined sweet spot: outputs that are unmistakably related, visually coherent, and yet each one surprising. Cherniak's &lt;em&gt;Ringers&lt;/em&gt; demonstrates that extreme constraint — a ball, a peg, a string — produces extraordinary variety when the parameter space is richly designed.&lt;/p&gt;

&lt;p&gt;What connects Molnár to Cherniak across six decades is not the medium. It is the method: &lt;em&gt;design the system, trust the emergence, resist the urge to control the specific output&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Makes a System Good
&lt;/h2&gt;

&lt;p&gt;A generative system is not evaluated the way a painting is evaluated. You cannot judge it by looking at a single output. You have to think about the &lt;em&gt;territory&lt;/em&gt; it covers.&lt;/p&gt;

&lt;p&gt;A good generative system has &lt;strong&gt;shared DNA across its outputs&lt;/strong&gt;. Look at a hundred pieces from Tyler Hobbs's Fidenza and you know immediately they came from the same mind, the same set of rules. They vary — wildly, interestingly — but they vary within a recognisable aesthetic space. This is what distinguishes a &lt;em&gt;system with aesthetic identity&lt;/em&gt; from a system that just produces random things. The constraints are what give the work its signature.&lt;/p&gt;

&lt;p&gt;A good generative system has &lt;strong&gt;no dead zones&lt;/strong&gt;. Every seed should produce something worth looking at. This sounds easy. It is not. Edge cases in parameter space produce edge cases in output space. The system that generates something extraordinary at seed 1234 might generate something completely dead at seed 1235. Finding and eliminating dead zones is a large part of the actual work of generative art — not the mathematics, not the code, but the exploration of the territory the code defines.&lt;/p&gt;

&lt;p&gt;A good generative system has &lt;strong&gt;latent depth&lt;/strong&gt; — structure that reveals itself slowly, that rewards close inspection. The first glance shows the gross shape. The second shows the internal variation. The third shows something you missed before. This is not an accident. It is engineered by composing techniques at multiple scales: coarse structure from one noise layer, medium detail from another, fine texture from a third.&lt;/p&gt;

&lt;p&gt;This is what the fractal noise extension from the previous post was doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;fractal-noise&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;reduce&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;freq&lt;/span&gt; &lt;span class="nv"&gt;amp&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;amp&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="mi"&gt;0&lt;/span&gt;
          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;map&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.008&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;range&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each octave adds a layer of detail at a finer scale, with a correspondingly smaller amplitude. The mountains are defined at the coarsest scale; the rocky outcrops at the medium scale; the texture of individual stones at the finest. Sum them, and the terrain has the depth of a real landscape — not because we modelled geology, but because we structured the randomness at multiple scales. This is the technique behind virtually every realistic-looking procedural landscape ever created, from Minecraft to flight simulators.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Authorship Question
&lt;/h2&gt;

&lt;p&gt;Here it is. The question you have been building toward since you started reading this.&lt;/p&gt;

&lt;p&gt;The terrain shifted in a way you did not design. A mountain rose at exactly the right position, at exactly the right height, at exactly the right moment in the animation. It looked &lt;em&gt;intentional&lt;/em&gt;. It looked like you planned it. You did not.&lt;/p&gt;

&lt;p&gt;Who made it?&lt;/p&gt;

&lt;p&gt;The options are not as simple as they first appear.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You made it.&lt;/strong&gt; You chose the noise function. You chose the spatial frequency. You chose the amplitude. You chose the colour mapping. Every aesthetic property of that mountain — the fact that it rises slowly, that it has that particular shade of green at its peak, that it moves at that particular pace — flows directly from decisions you made. The mountain could not have appeared without those decisions. In what sense did you not make it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The algorithm made it.&lt;/strong&gt; You did not choose this mountain. You could not have. The specific configuration of peaks and valleys at frame 1,247 of this particular seed was not in your mind when you wrote the code. It is the result of the noise function's behaviour at those coordinates — a mathematical fact you could have computed but certainly did not imagine. In what sense did you make it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The seed made it.&lt;/strong&gt; The seed is the number that initialises the noise function. Change it and you get a different mountain at frame 1,247. The seed is, in some sense, the &lt;em&gt;identity&lt;/em&gt; of this particular piece. It is what makes this terrain &lt;em&gt;this terrain&lt;/em&gt; rather than another one. The collector of an on-chain generative artwork knows they own token 42 — which is to say, seed 42 — which is to say, the specific possibility that seed 42 selects from the artist's possibility space. In what sense is the seed not an author?&lt;/p&gt;

&lt;p&gt;Philip Galanter, writing in 2003, proposed that the right frame is not authorship at all — it is &lt;em&gt;complexity theory&lt;/em&gt;. The generative artist is a &lt;em&gt;complexity tuner&lt;/em&gt;, operating at the boundary between order and chaos, exploiting the dynamics of the systems they build. The question of credit misses the point. The interesting question is what the work does, not who did it.&lt;/p&gt;

&lt;p&gt;I find this convincing but incomplete. It describes the &lt;em&gt;method&lt;/em&gt; without describing the &lt;em&gt;experience&lt;/em&gt;. And the experience — of finding meaning in structure, of feeling surprise at your own system's output, of recognising your aesthetic in something you did not design — is real and philosophically significant.&lt;/p&gt;

&lt;p&gt;Here is my own view, offered without confidence: generative art is &lt;strong&gt;collaborative authorship across three parties&lt;/strong&gt; — the human designer, the algorithm, and the seed. The human designs the possibility space. The algorithm enforces the rules of that space. The seed selects a specific realisation. None of the three alone produces the work. All three together do.&lt;/p&gt;

&lt;p&gt;This is not so strange if you think about it. A jazz musician collaborates with their instrument, with the acoustics of the room, with the other musicians, with the history of the form. The specific improvisation that emerged at 9:47pm on a Tuesday in 1965 required all of those collaborators. No one seriously argues that the musician did not make the music. No one seriously argues they made it alone.&lt;/p&gt;

&lt;p&gt;The generative artist did not hold the brush. But they designed the brush, and they chose to hold nothing else.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Misconceptions Worth Clearing
&lt;/h2&gt;

&lt;p&gt;Three misconceptions circulate about generative art, and they obscure what is actually interesting about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"The AI makes it."&lt;/strong&gt; Most generative art has nothing to do with machine learning. The Perlin terrain sketch we built uses a deterministic mathematical function. So does Fidenza. So did Vera Molnár's plotter drawings. Machine learning is one tool that &lt;em&gt;can&lt;/em&gt; be used in generative contexts, but conflating ML with generative art mistakes a small recent subfield for the entire category.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"It's random, so it's easy."&lt;/strong&gt; Taming randomness is the hard part. Pure random noise is trivial to produce and immediately boring. The craft is in constraining the randomness, in finding the parameters and rules that make the random outputs &lt;em&gt;good&lt;/em&gt; — that eliminate the dead zones, that build in the latent depth, that tune the dial to the sweet spot. This work is as demanding as any other art-making practice. It is just less legible to observers who do not know how to look for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"The computer is the artist."&lt;/strong&gt; The computer is not the artist any more than the camera is the photographer or the piano is the composer. It is a medium with its own properties, its own affordances, its own resistances. The artist works with and against those properties. The specific character of the work is shaped by the medium — but it is shaped &lt;em&gt;by&lt;/em&gt; the artist working in it.&lt;/p&gt;




&lt;h2&gt;
  
  
  What This Means for the Code You Write
&lt;/h2&gt;

&lt;p&gt;If you write generative code — even casually, even experimentally — you are participating in a practice with sixty years of history and a genuinely unresolved philosophical core. The parameter tuning is not incidental. It is the aesthetic work. The seed that produces the surprising output is not luck — it is the system functioning as designed, revealing a corner of the territory you mapped.&lt;/p&gt;

&lt;p&gt;When you adjust the x-scale of the noise from &lt;code&gt;0.008&lt;/code&gt; to &lt;code&gt;0.003&lt;/code&gt; and the terrain suddenly feels oceanic rather than mountainous — that feeling is data. It is your aesthetic judgment recognizing that you have moved along the spectrum in a direction that suits your intent. Trust it. The REPL makes this loop fast enough to be intuitive, to feel less like programming and more like sculpting.&lt;/p&gt;

&lt;p&gt;The terrain sketch from the previous post is a simple system. Its parameter space is small. But the same logic scales to systems of enormous complexity — systems with hundreds of parameters, with internal feedback loops, with emergent behaviours that resist prediction even by their creators.&lt;/p&gt;

&lt;p&gt;The first step is the same: write the system. Then explore what it made.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Closing Provocation
&lt;/h2&gt;

&lt;p&gt;We have spent this whole post asking who made the artwork. Let me end with a different question.&lt;/p&gt;

&lt;p&gt;Does it matter?&lt;/p&gt;

&lt;p&gt;If a mountain appears on the screen and it is beautiful — if it has that precise quality of &lt;em&gt;feeling right&lt;/em&gt;, of feeling like it belongs, of surprising you while also feeling inevitable — does the question of authorship change that? Does knowing that a noise function produced it rather than a decision make it less beautiful? Does knowing that the artist designed the noise function rather than the specific mountain make it less theirs?&lt;/p&gt;

&lt;p&gt;I do not think aesthetics is downstream of authorship. I think it runs the other way. The question of who made something is interesting philosophically, legally, economically. But the experience of standing in front of something — or sitting in front of a screen, watching a landscape scroll — is prior to all of that. The experience arrives before the question.&lt;/p&gt;

&lt;p&gt;Vera Molnár said she was looking for forms that &lt;em&gt;move&lt;/em&gt; her. She was not asking who was responsible for them.&lt;/p&gt;

&lt;p&gt;Maybe that is the generative artist's actual job: design a system capable of producing something that moves you. And then let it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Going Further
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://quil.info/" rel="noopener noreferrer"&gt;Quil Documentation&lt;/a&gt; — the Clojure/Processing wrapper used in this series&lt;/li&gt;
&lt;li&gt;Tyler Hobbs — &lt;em&gt;&lt;a href="https://tylerxhobbs.com/essays/2021/the-aesthetics-of-generative-art" rel="noopener noreferrer"&gt;The Aesthetics of Generative Art&lt;/a&gt;&lt;/em&gt; — the best contemporary essay on the craft&lt;/li&gt;
&lt;li&gt;Philip Galanter — &lt;em&gt;What is Generative Art? Complexity Theory as a Context for Art Theory&lt;/em&gt; (2003) — the theoretical foundation&lt;/li&gt;
&lt;li&gt;Vera Molnár — &lt;em&gt;&lt;a href="https://www.atariarchives.org/artist/sec11.php" rel="noopener noreferrer"&gt;Toward Aesthetic Computation&lt;/a&gt;&lt;/em&gt; (1975) — the original source&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://thebookofshaders.com/" rel="noopener noreferrer"&gt;The Book of Shaders&lt;/a&gt; — noise, fractals, and colour, explained visually&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.generative-gestaltung.de/2/" rel="noopener noreferrer"&gt;Generative Gestaltung&lt;/a&gt; — code and book, the definitive reference for creative coding&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Series Navigation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part 1:&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;&lt;em&gt;The Invisible Brush: Generative Art and the Algorithms That Paint&lt;/em&gt;&lt;/a&gt; — Foundations of PCG, noise functions, and building a terrain generator in Clojure and Quil.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2 (Current):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e"&gt;&lt;em&gt;Who Made This? The Author Shift and the Philosophy of Generative Art&lt;/em&gt;&lt;/a&gt; — Deconstructs the author shift, the spectrum of control, and 60 years of algorithmic art philosophy.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;What does authorship mean to you in this context — do you feel like the artist of the outputs your systems produce, or something else? Leave a comment. I'm genuinely curious where you land.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>generativeart</category>
      <category>creativecoding</category>
      <category>clojure</category>
      <category>philosophy</category>
    </item>
    <item>
      <title>The Invisible Brush: Generative Art and the Algorithms That Paint</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Sat, 14 Nov 2026 12:32:16 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig</link>
      <guid>https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is **Part 1&lt;/em&gt;* of a 3-part series on &lt;strong&gt;The Invisible Brush: Generative Art &amp;amp; Creative Computation&lt;/strong&gt;:*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part 1: The Invisible Brush — Generative Art and the Algorithms That Paint&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e"&gt;Part 2: Who Made This? The Author Shift and the Philosophy of Generative Art&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/breaking-the-2d-plane-opengl-shaders-and-the-3d-graphics-pipeline-in-clojure-quil-3663"&gt;Part 3: Breaking the 2D Plane — OpenGL, Shaders, and the 3D Graphics Pipeline in Clojure &amp;amp; Quil&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;A long-form exploration of Procedural Content Generation as a creative engine — with Clojure and Quil.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There is a particular kind of wonder that comes from watching something grow on a screen that you did not draw. A tree that branches unpredictably. A coastline that stretches further than any hand could trace. A galaxy of stars no astronomer catalogued. You wrote the rules, but the world surprised you anyway.&lt;/p&gt;

&lt;p&gt;This is the promise of &lt;strong&gt;Procedural Content Generation&lt;/strong&gt; — and it sits quietly at the heart of generative art.&lt;/p&gt;

&lt;p&gt;This post is for developers who can read code but have never thought of algorithms as paintbrushes. By the end, you will have a working piece of generative art in Clojure, a mental model of the major PCG techniques, and perhaps a small shift in how you think about creativity itself.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is Procedural Content Generation?
&lt;/h2&gt;

&lt;p&gt;At its core, PCG is disarmingly simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;seed → algorithm → content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You give the algorithm a number — a seed — and it produces something: terrain, a name, a dungeon, a melody, a painting. Change the seed and you get a different result. Same seed, same result every time. The content is not stored; it is &lt;em&gt;computed on demand&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This is not random noise. It is &lt;em&gt;structured randomness&lt;/em&gt; — randomness with rules, with memory, with intention baked in.&lt;/p&gt;

&lt;p&gt;The implications are profound. The game &lt;em&gt;Elite&lt;/em&gt; (1984) shipped with eight galaxies — 256 star systems each, 2,048 total — with planets, economies, and names — on a 32KB floppy disk. None of it was stored. Every system was generated from a single seed, every time the game ran. What could not fit in storage fit in an algorithm.&lt;/p&gt;

&lt;p&gt;No Man's Sky does something similar at a scale that strains comprehension: 18 quintillion planets, each with unique geography, atmosphere, flora, and fauna — all from a compact install. The difference between today and 1984 is not philosophy; it is processing power.&lt;/p&gt;

&lt;p&gt;But PCG is not just an engineering trick. It is a &lt;em&gt;creative philosophy&lt;/em&gt;. And nowhere is that more visible than in generative art.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Techniques: A Field Guide
&lt;/h2&gt;

&lt;p&gt;Before we write any code, let us walk the landscape. PCG is not one thing — it is a family of techniques, each with its own personality and aesthetic fingerprint.&lt;/p&gt;

&lt;h3&gt;
  
  
  Noise Functions (Perlin, Simplex)
&lt;/h3&gt;

&lt;p&gt;The workhorse of generative visuals. Noise functions produce smooth, continuous pseudo-random values across space. Feed them an &lt;code&gt;x&lt;/code&gt; coordinate and get a value between 0 and 1. Feed them &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; and you get a 2D field — a heightmap, a cloud, a terrain.&lt;/p&gt;

&lt;p&gt;The key property is &lt;em&gt;coherence&lt;/em&gt;: nearby points have similar values, so the output looks organic rather than static. Ken Perlin invented his noise function in 1983, inspired by his frustration with the sterile look of computer graphics while working on &lt;em&gt;Tron&lt;/em&gt;. He published it at SIGGRAPH 1985 — and it earned him a Technical Academy Award in 1997. It has been in every serious generative art toolkit since.&lt;/p&gt;

&lt;p&gt;Minecraft's terrain is Perlin noise, layered. The rolling hills, the sudden cliffs, the underground cave networks — all noise, composed.&lt;/p&gt;

&lt;h3&gt;
  
  
  L-Systems
&lt;/h3&gt;

&lt;p&gt;Invented by biologist Aristid Lindenmayer in 1968 to model plant growth, L-Systems are rewriting rules applied repeatedly to a string of symbols. Start with &lt;code&gt;X&lt;/code&gt;. Apply rules. &lt;code&gt;X&lt;/code&gt; becomes &lt;code&gt;F+[[X]-X]-F[-FX]+X&lt;/code&gt;. Apply again. The string grows. Eventually you interpret each character as a drawing command — move forward, turn left, push position onto a stack — and you have a tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight brainfuck"&gt;&lt;code&gt;&lt;span class="no"&gt;F&lt;/span&gt; → &lt;span class="n"&gt;move&lt;/span&gt; &lt;span class="n"&gt;forward&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt; → &lt;span class="n"&gt;turn&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; → &lt;span class="n"&gt;turn&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt; → &lt;span class="k"&gt;push&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt; → &lt;span class="k"&gt;pop&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The beauty of L-Systems is emergence: a small set of rules, iterated, produces complexity that looks designed by nature. Because it was. Lindenmayer was modelling algae.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wave Function Collapse (WFC)
&lt;/h3&gt;

&lt;p&gt;The new kid on the block, and currently the most talked-about technique in generative level design. WFC works by observing a small sample image or tileset and learning which tiles can appear next to which other tiles. It then generates a new image by collapsing possibilities, one cell at a time, always respecting the learned constraints.&lt;/p&gt;

&lt;p&gt;The output looks hand-crafted because it learned from hand-crafted input. It is generative but not wild — it is &lt;em&gt;faithful to a style&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Grammar-Based Generation
&lt;/h3&gt;

&lt;p&gt;Text adventure games, quest generators, and NPC dialogue all lean on grammars. You define production rules — &lt;code&gt;&amp;lt;quest&amp;gt; → &amp;lt;hero&amp;gt; must &amp;lt;action&amp;gt; &amp;lt;object&amp;gt;&lt;/code&gt; — and expand them recursively. Tracery, a tool by Kate Compton, makes this accessible enough to feel like play.&lt;/p&gt;

&lt;h3&gt;
  
  
  BSP Trees
&lt;/h3&gt;

&lt;p&gt;Binary Space Partitioning divides a rectangle into two sub-rectangles, then divides those, recursively. Place rooms at the leaves, connect them with corridors, and you have a dungeon. Doom used BSP trees for rendering; roguelikes use them for level generation. The algorithm is old, simple, and reliable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Voronoi Diagrams
&lt;/h3&gt;

&lt;p&gt;Scatter points on a plane. For each point on the plane, ask: which of my scattered points is closest? Colour each region by its nearest point. The result is a diagram that looks uncannily like biological cells, geographic territories, cracked earth. Civilization uses Voronoi for map regions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Markov Chains
&lt;/h3&gt;

&lt;p&gt;A Markov chain generates sequences where each step depends only on the current state. Feed it enough text and it learns transition probabilities. Ask it to generate and it produces text that &lt;em&gt;sounds like&lt;/em&gt; the source — statistically plausible, semantically strange. Fantasy name generators, lorem ipsum variants, and low-quality content farms all use Markov chains.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cellular Automata
&lt;/h3&gt;

&lt;p&gt;Conway's Game of Life is the canonical example. Each cell is alive or dead. Each tick, the cell looks at its neighbours and applies a rule. What emerges from these local interactions can be astonishingly complex: gliders, oscillators, and patterns that resist prediction. For cave generation in roguelikes, a simple birth/death rule applied to a noisy grid smooths it into something that looks carved by water.&lt;/p&gt;




&lt;h2&gt;
  
  
  The PCG Stack
&lt;/h2&gt;

&lt;p&gt;These techniques rarely live alone. In practice, generative systems &lt;em&gt;compose&lt;/em&gt; them into layers, each one consuming the output of the last:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Raw noise
  → Terrain shape
    → Biome placement
      → Resource distribution
        → Structure placement
          → Enemy/NPC population
            → Loot tables
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bottom of the stack is mathematical. The top is semantic. PCG is the act of building the ladder between them.&lt;/p&gt;

&lt;p&gt;In generative art, this stack might look different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Noise field
  → Form silhouettes
    → Colour palette selection
      → Stroke variation
        → Composition rules
          → Final render
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same philosophy. Different aesthetic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Clojure?
&lt;/h2&gt;

&lt;p&gt;Before we write code, it is worth asking: why Clojure specifically?&lt;/p&gt;

&lt;p&gt;The honest answer is the REPL.&lt;/p&gt;

&lt;p&gt;Generative art is an iterative, exploratory craft. You have an idea. You try it. It is not quite right. You adjust a parameter. You try again. You repeat this loop dozens of times before you find the version that feels alive. The cycle between idea and feedback needs to be short — ideally, instantaneous.&lt;/p&gt;

&lt;p&gt;Clojure's REPL is live. You change a function and re-evaluate it without restarting the program. With Quil (Clojure's Processing wrapper), that means the canvas repaints with your new logic while you are still looking at it. No recompile. No restart. No lost state.&lt;/p&gt;

&lt;p&gt;This is not a minor convenience. It changes the nature of the work. You are not programming at the algorithm — you are &lt;em&gt;in conversation&lt;/em&gt; with it.&lt;/p&gt;

&lt;p&gt;Additionally, Clojure's functional core maps naturally to generative thinking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;iterate&lt;/code&gt; produces an infinite sequence of transformations — perfect for L-System expansion or animated frames&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lazy-seq&lt;/code&gt; lets you define an infinite generative stream without computing it all upfront&lt;/li&gt;
&lt;li&gt;Immutable data makes it easy to reason about state across frames&lt;/li&gt;
&lt;li&gt;The threading macros (&lt;code&gt;-&amp;gt;&lt;/code&gt;, &lt;code&gt;-&amp;gt;&amp;gt;&lt;/code&gt;) make pipelines readable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  A Working Quil Sketch: Perlin Noise Terrain
&lt;/h2&gt;

&lt;p&gt;Let us build something. We will create an animated terrain strip — a cross-section of landscape that shifts slowly over time, as if seen through a moving window. The technique is simple: Perlin noise sampled at increasing x positions, with time as a second dimension so the terrain evolves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;Add Quil to your &lt;code&gt;deps.edn&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:deps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;quil/quil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:mvn/version&lt;/span&gt; &lt;span class="s2"&gt;"4.3.1563"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Sketch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;generative.terrain&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;quil.core&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;q&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;quil.middleware&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; --- State ---&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;initial-state&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;; time offset — drives animation&lt;/span&gt;

&lt;span class="c1"&gt;;; --- Update ---&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;update-state&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.005&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;; advance time slowly each frame&lt;/span&gt;

&lt;span class="c1"&gt;;; --- Draw ---&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;terrain-height&lt;/span&gt;
  &lt;span class="s2"&gt;"Returns a y-coordinate for column x at time t.
   Perlin noise gives a smooth, organic value in [0, 1].
   We scale it to fill the lower portion of the canvas."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;noise-val&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mf"&gt;0.008&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;; x-scale controls terrain frequency&lt;/span&gt;
        &lt;span class="nv"&gt;base&lt;/span&gt;      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;; terrain fills bottom 40–90% of canvas&lt;/span&gt;
        &lt;span class="nv"&gt;amplitude&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;base&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;noise-val&lt;/span&gt; &lt;span class="nv"&gt;amplitude&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;draw-sky&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;;; Gradient sky: deep indigo at top fading to dark slate&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;doseq&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;y&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;range&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;y&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="nv"&gt;r&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/lerp&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="nv"&gt;g&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/lerp&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="nv"&gt;b&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/lerp&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/stroke&lt;/span&gt; &lt;span class="nv"&gt;r&lt;/span&gt; &lt;span class="nv"&gt;g&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/line&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;y&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;draw-terrain&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;canvas-width&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;;; Draw each vertical column of terrain as a filled rectangle&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/no-stroke&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;doseq&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;range&lt;/span&gt; &lt;span class="nv"&gt;canvas-width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;h&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;terrain-height&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="c1"&gt;;; Colour shifts slightly with height: darker valleys, lighter peaks&lt;/span&gt;
          &lt;span class="nv"&gt;brightness&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/map-range&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;
                                  &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt;
                                  &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/fill&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="nv"&gt;brightness&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/rect&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;canvas-height&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;draw-state&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;w&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/width&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;h&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:t&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;draw-sky&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;draw-terrain&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;w&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; --- Sketch Entry Point ---&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;setup&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/frame-rate&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/color-mode&lt;/span&gt; &lt;span class="ss"&gt;:rgb&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;initial-state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/defsketch&lt;/span&gt; &lt;span class="nv"&gt;terrain&lt;/span&gt;
  &lt;span class="ss"&gt;:title&lt;/span&gt;      &lt;span class="s2"&gt;"Perlin Terrain"&lt;/span&gt;
  &lt;span class="ss"&gt;:size&lt;/span&gt;       &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="ss"&gt;:setup&lt;/span&gt;      &lt;span class="nv"&gt;setup&lt;/span&gt;
  &lt;span class="ss"&gt;:update&lt;/span&gt;     &lt;span class="nv"&gt;update-state&lt;/span&gt;
  &lt;span class="ss"&gt;:draw&lt;/span&gt;       &lt;span class="nv"&gt;draw-state&lt;/span&gt;
  &lt;span class="ss"&gt;:middleware&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;m/fun-mode&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;; functional mode: state flows through update → draw&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running It
&lt;/h3&gt;

&lt;p&gt;Ensure your code is saved at &lt;code&gt;src/generative/terrain.clj&lt;/code&gt; and your &lt;code&gt;deps.edn&lt;/code&gt; includes &lt;code&gt;{:paths ["src"]}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure -M -m generative.terrain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A window will open. You will see a dark landscape scrolling — hills rising and falling organically, their colour shifting with elevation. The terrain is not stored anywhere. It is computed, column by column, frame by frame, from two floating-point numbers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exploring the Parameters
&lt;/h3&gt;

&lt;p&gt;This is where the REPL shines. Try changing these values and re-evaluating:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter (default)&lt;/th&gt;
&lt;th&gt;Effect of increasing&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;0.008&lt;/code&gt; (x-scale)&lt;/td&gt;
&lt;td&gt;More jagged, chaotic terrain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;0.005&lt;/code&gt; (time step)&lt;/td&gt;
&lt;td&gt;Faster animation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;0.5&lt;/code&gt; (amplitude)&lt;/td&gt;
&lt;td&gt;Taller mountains&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;0.4&lt;/code&gt; (base)&lt;/td&gt;
&lt;td&gt;Terrain sits higher in frame&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each parameter is a dial. Turn them. Notice how the aesthetic shifts. This is the generative art workflow — not designing the output, but designing the &lt;em&gt;space of possible outputs&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Composing Techniques
&lt;/h2&gt;

&lt;p&gt;The sketch above uses only noise. But generative art rewards composition. Here are a few extensions to try:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add an L-System tree on the horizon.&lt;/strong&gt; Expand a plant grammar, interpret the string as turtle-graphics commands, and plant the result at a terrain peak. The noise provides context; the L-System provides detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer noise at different frequencies.&lt;/strong&gt; Sample noise at fine scale (high frequency) for rocky texture, medium scale for hill shape, and coarse scale for continental slope. Sum them with decreasing weights. This is called &lt;em&gt;fractal noise&lt;/em&gt; or &lt;em&gt;octave layering&lt;/em&gt; — the technique behind most realistic-looking procedural terrain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;fractal-noise&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;reduce&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;freq&lt;/span&gt; &lt;span class="nv"&gt;amp&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;amp&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;q/noise&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="nv"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="mi"&gt;0&lt;/span&gt;
          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;map&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.008&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Math/pow&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;range&lt;/span&gt; &lt;span class="nv"&gt;octaves&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use Voronoi cells for a stained-glass palette.&lt;/strong&gt; Generate a set of random seed points. For each pixel, find the nearest seed. Assign colours by seed index. The result is a mosaic that looks hand-designed but is entirely computed.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Deeper Question
&lt;/h2&gt;

&lt;p&gt;There is a question that every generative artist eventually confronts, usually late at night after a long session of parameter tuning:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Is this art? Or is it the algorithm's art?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It is the wrong question — but it is a useful wrong question.&lt;/p&gt;

&lt;p&gt;When you write a generative system, you are not making choices about what the final image looks like. You are making choices about what &lt;em&gt;kinds of images are possible&lt;/em&gt;. You are designing a phase space, a territory of outcomes, and then exploring it with seeds.&lt;/p&gt;

&lt;p&gt;This is not so different from a painter choosing a palette, a canvas size, and a technique — and then following where the work leads. The painter does not fully control the painting either. Accidents happen. Happy ones. The wet paint bleeds in ways the brush did not intend. The generative artist's accident is the seed they did not expect.&lt;/p&gt;

&lt;p&gt;The algorithm is not the artist. But it is not merely a tool, either. It is a &lt;em&gt;collaborator&lt;/em&gt; — one with no preferences of its own, but whose behaviour emerges from every decision you embedded in it.&lt;/p&gt;

&lt;p&gt;When the terrain shifts in ways that surprise you — when you see a mountain range you did not plan, a valley that feels like it means something — that is not the algorithm feeling. That is you, finding meaning in structure. Which is what humans do with everything: clouds, wood grain, the patterns in spilled coffee.&lt;/p&gt;

&lt;p&gt;Procedural content generation does not replace the artist. It gives the artist a new kind of canvas: one that grows, one that surprises, one that generates faster than any hand could move.&lt;/p&gt;

&lt;p&gt;The brush was always invisible. It was always mathematics. We just made it legible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://quil.info/" rel="noopener noreferrer"&gt;Quil Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://thebookofshaders.com/" rel="noopener noreferrer"&gt;The Book of Shaders&lt;/a&gt; — noise functions explained visually (GLSL, but the math translates)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tracery.io/" rel="noopener noreferrer"&gt;Tracery&lt;/a&gt; — grammar-based generation made playful&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.redblobgames.com/" rel="noopener noreferrer"&gt;Red Blob Games&lt;/a&gt; — the finest visual explanations of PCG algorithms on the internet&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.generative-gestaltung.de/2/" rel="noopener noreferrer"&gt;Generative Gestaltung&lt;/a&gt; — a book and code library for creative coding&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://thecodingtrain.com/" rel="noopener noreferrer"&gt;The Coding Train&lt;/a&gt; — Daniel Shiffman's video series covers noise, L-Systems, cellular automata with infectious enthusiasm&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Series Navigation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 (Current):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-invisible-brush-generative-art-and-the-algorithms-that-paint-32ig"&gt;&lt;em&gt;The Invisible Brush: Generative Art and the Algorithms That Paint&lt;/em&gt;&lt;/a&gt; — Foundations of PCG, noise functions, and building a terrain generator in Clojure and Quil.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2:&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/who-made-this-the-author-shift-and-the-philosophy-of-generative-art-o3e"&gt;&lt;em&gt;Who Made This? The Author Shift and the Philosophy of Generative Art&lt;/em&gt;&lt;/a&gt; — Deconstructs the author shift, the spectrum of control, and 60 years of algorithmic art philosophy.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Have you experimented with creative coding or procedural generation in Clojure or other functional languages? What is your favorite generative technique? Drop a comment or share your sketches below!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy generating.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>creativecoding</category>
      <category>gamedev</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Full-Stack Case for Clojure: AI, Concurrency, and Regulatory Reality</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Fri, 13 Nov 2026 12:38:44 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/the-full-stack-case-for-clojure-ai-concurrency-and-regulatory-reality-4oh4</link>
      <guid>https://dev.to/ganesh_rajendran_art/the-full-stack-case-for-clojure-ai-concurrency-and-regulatory-reality-4oh4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is **Part 3&lt;/em&gt;* of a 3-part series on &lt;strong&gt;The Economics of Memory Safety&lt;/strong&gt;:*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/the-economics-of-memory-safety-inaction-vs-the-cost-of-rewriting-43in"&gt;Part 1: The Economics of Memory Safety — Inaction vs. The Cost of Rewriting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b"&gt;Part 2: Beyond the Rewrite Trap — High-Velocity Memory Safety with Clojure and Tiered Systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 3: The Full-Stack Case for Clojure — AI, Concurrency, and Regulatory Reality&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;




&lt;p&gt;In &lt;a href="https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b"&gt;&lt;em&gt;Beyond the Rewrite Trap&lt;/em&gt;&lt;/a&gt;, we established that Clojure's managed runtime eliminates 13 categories of memory corruption hazards while maintaining feature delivery velocity that monolithic rewrites cannot match. That argument was grounded in regulatory mandates — CISA, ONCD, the EU Cyber Resilience Act.&lt;/p&gt;

&lt;p&gt;But memory safety is only one dimension of the case.&lt;/p&gt;

&lt;p&gt;Three forces are reshaping software architecture in 2024–2026 at unprecedented speed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AI proliferation:&lt;/strong&gt; Every engineering organization is now running inference pipelines, embedding stores, LLM prompt chains, and streaming data transformations — often bolted onto stacks that were not designed for safe, composable data flow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed systems complexity:&lt;/strong&gt; Microservice sprawl has created coordination overhead that is consuming teams faster than it is delivering value. Organizations are actively consolidating.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regulatory mandates:&lt;/strong&gt; Memory safety compliance requirements are now procurement blockers. The EU CRA, CISA roadmaps, and White House ONCD guidance are not advisory — they carry contractual and financial consequences.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The question this article addresses is broader than memory safety: &lt;strong&gt;Is Clojure's design philosophy — immutability by default, managed concurrency primitives, a live REPL, a small composable core — the most coherent response to this confluence of forces?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is the evidence.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Framework Complexity Tax: Clojure's Small Core vs. the Industry
&lt;/h2&gt;

&lt;p&gt;Modern backend stacks have accumulated a staggering complexity overhead. A production Spring Boot service ships with hundreds of transitive dependencies, annotation processors, reflection configuration, an XML/YAML hierarchy for environment switching, and a startup sequence that takes seconds. Django and Rails improved ergonomics at the cost of absorbing Rails idioms as architecture constraints.&lt;/p&gt;

&lt;p&gt;This complexity compounds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dependency graphs become unauditable.&lt;/li&gt;
&lt;li&gt;Security advisories arrive faster than teams can triage.&lt;/li&gt;
&lt;li&gt;Onboarding new engineers requires weeks of framework-specific orientation before the domain becomes legible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clojure's answer is radical minimalism. The language core — &lt;code&gt;clojure.core&lt;/code&gt; — is approximately &lt;strong&gt;600 functions&lt;/strong&gt;. The standard library ships no web framework, no ORM, no dependency injection container. Instead, the ecosystem standardizes on thin, data-driven libraries composed together: &lt;code&gt;reitit&lt;/code&gt; and &lt;code&gt;malli&lt;/code&gt; for routing and schema coercion, &lt;code&gt;next.jdbc&lt;/code&gt; and &lt;code&gt;honeysql&lt;/code&gt; for declarative SQL generation, and &lt;code&gt;integrant&lt;/code&gt; for lifecycle configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; A complete, production-grade HTTP service configuration in Clojure&lt;/span&gt;
&lt;span class="c1"&gt;;; No annotation processors. No XML. No reflection config.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;system-config&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:server/http&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:port&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt; &lt;span class="ss"&gt;:handler&lt;/span&gt; &lt;span class="nv"&gt;#'app/router&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="ss"&gt;:db/connection&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:jdbc-url&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;System/getenv&lt;/span&gt; &lt;span class="s2"&gt;"DATABASE_URL"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="ss"&gt;:cache/redis&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:uri&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;System/getenv&lt;/span&gt; &lt;span class="s2"&gt;"REDIS_URL"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="ss"&gt;:schema/validate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:registry&lt;/span&gt; &lt;span class="nv"&gt;schema/registry&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not a simplified example. This &lt;em&gt;is&lt;/em&gt; the configuration — a plain Clojure map that any editor, REPL, test, or migration script can inspect, transform, and validate without framework-specific tooling.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Dependency Audit Advantage
&lt;/h3&gt;

&lt;p&gt;A typical Clojure production service has &lt;strong&gt;15 to 40 direct dependencies&lt;/strong&gt;. A comparable Spring Boot service routinely carries &lt;strong&gt;150 to 300&lt;/strong&gt;. Each dependency is an attack surface, a potential CVE, and a maintenance burden. For organizations operating under supply chain security requirements (SSDF, EU CRA Article 13), a smaller, auditable dependency graph is a direct compliance asset.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The AI-Era Data Pipeline: Immutability as the Native Primitive
&lt;/h2&gt;

&lt;p&gt;The defining engineering problem right now is not compute — it is &lt;strong&gt;safe, composable data transformation at scale&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;LLM pipelines ingest unstructured inputs, embed them, rank them, augment them with retrieval, pass them through prompt templates, parse structured outputs, validate them against schemas, and persist results. Every step produces data that feeds the next. If any step mutates shared state, the pipeline becomes non-deterministic, difficult to replay, and impossible to test in isolation.&lt;/p&gt;

&lt;p&gt;This is precisely the problem Clojure was designed to solve. Persistent immutable data structures mean that every transformation yields a new value. The original is never mutated. The pipeline is a sequence of pure functions over data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;ai.pipeline&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;malli.core&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ai.embeddings&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;embed&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ai.retrieval&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;retrieval&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ai.llm&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Each stage is a pure function: data in, data out. No shared mutable state.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;run-rag-pipeline&lt;/span&gt;
  &lt;span class="s2"&gt;"Retrieval-Augmented Generation pipeline. Pure, composable, replayable."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;user-query&lt;/span&gt; &lt;span class="nv"&gt;context-config&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:query&lt;/span&gt;    &lt;span class="nv"&gt;user-query&lt;/span&gt;
       &lt;span class="ss"&gt;:config&lt;/span&gt;   &lt;span class="nv"&gt;context-config&lt;/span&gt;
       &lt;span class="ss"&gt;:trace-id&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;random-uuid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nv"&gt;embed/vectorize-query&lt;/span&gt;          &lt;span class="c1"&gt;;; Adds :embedding vector, returns new map&lt;/span&gt;
      &lt;span class="nv"&gt;retrieval/fetch-top-k-chunks&lt;/span&gt;   &lt;span class="c1"&gt;;; Adds :chunks, returns new map&lt;/span&gt;
      &lt;span class="nv"&gt;llm/build-augmented-prompt&lt;/span&gt;     &lt;span class="c1"&gt;;; Adds :prompt, returns new map&lt;/span&gt;
      &lt;span class="nv"&gt;llm/submit-inference&lt;/span&gt;           &lt;span class="c1"&gt;;; Adds :response, returns new map&lt;/span&gt;
      &lt;span class="nv"&gt;validate-output-schema&lt;/span&gt;         &lt;span class="c1"&gt;;; Throws on schema violation&lt;/span&gt;
      &lt;span class="nv"&gt;persist-trace&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                &lt;span class="c1"&gt;;; Returns final map with :trace persisted&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each function in this &lt;code&gt;-&amp;gt;&lt;/code&gt; pipeline receives an immutable map and returns an enriched one. Any step can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unit tested in isolation&lt;/strong&gt; — just call the function with a test map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replayed from any checkpoint&lt;/strong&gt; — save the intermediate map, re-run from that stage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traced end-to-end&lt;/strong&gt; — the input and output of every step are values, not effects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compare this to Python's dominant pattern for ML pipelines, where mutable dictionaries, in-place NumPy array mutations, and global model registries produce pipelines that are notoriously difficult to unit test without end-to-end execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Schema-Validated LLM Contracts with Malli
&lt;/h3&gt;

&lt;p&gt;LLM outputs are notoriously unstructured. Clojure's &lt;code&gt;malli&lt;/code&gt; library provides expressive runtime schemas that enforce structural contracts at every boundary without the overhead of a static type system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;LLMResponseSchema&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:map&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:response/text&lt;/span&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ss"&gt;:max&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="c1"&gt;;; String enums match provider API identifiers. Extend as your model roster grows.&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:response/model&lt;/span&gt;   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;;; or use [:enum ...] for a fixed allowlist&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:response/tokens&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:map&lt;/span&gt;
                       &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:prompt&lt;/span&gt;   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ss"&gt;:max&lt;/span&gt; &lt;span class="mi"&gt;128000&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                       &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:completion&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ss"&gt;:max&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:response/latency-ms&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;validated-inference&lt;/span&gt;
  &lt;span class="s2"&gt;"Calls LLM and enforces structural contract on the response.
  Throws immediately with a detailed path-aware error on violation."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;prompt&lt;/span&gt; &lt;span class="nv"&gt;model-config&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;raw-response&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;llm/call!&lt;/span&gt; &lt;span class="nv"&gt;prompt&lt;/span&gt; &lt;span class="nv"&gt;model-config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;m/validate&lt;/span&gt; &lt;span class="nv"&gt;LLMResponseSchema&lt;/span&gt; &lt;span class="nv"&gt;raw-response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;raw-response&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ex-info&lt;/span&gt; &lt;span class="s2"&gt;"LLM response schema violation"&lt;/span&gt;
                      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:errors&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;m/explain&lt;/span&gt; &lt;span class="nv"&gt;LLMResponseSchema&lt;/span&gt; &lt;span class="nv"&gt;raw-response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                       &lt;span class="ss"&gt;:model&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:model&lt;/span&gt; &lt;span class="nv"&gt;model-config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not type-checking in the static sense — it is &lt;strong&gt;contract enforcement at the domain boundary&lt;/strong&gt;, exactly where unstructured AI outputs meet structured application logic. Malli's error messages include path-level diagnostics that are significantly more actionable than generic type errors.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. The Concurrency Model: Separating Identity from State
&lt;/h2&gt;

&lt;p&gt;The dominant concurrency abstractions in popular languages have known structural weaknesses:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language / Runtime&lt;/th&gt;
&lt;th&gt;Concurrency Model&lt;/th&gt;
&lt;th&gt;Known Failure Mode&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Python asyncio&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Cooperative, single-threaded event loop&lt;/td&gt;
&lt;td&gt;Blocking calls corrupt the event loop; CPU-bound work requires process isolation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Go goroutines + channels&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;M:N scheduling, explicit channels&lt;/td&gt;
&lt;td&gt;Channel deadlocks; shared mutable state via pointers requires discipline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Java/Kotlin threads + locks&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;OS thread pool + synchronized&lt;/td&gt;
&lt;td&gt;Lock inversion deadlocks; lost updates under contention&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Node.js event loop&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Single-threaded async&lt;/td&gt;
&lt;td&gt;Same as Python asyncio; long-running work blocks all concurrent requests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Clojure atoms + STM + core.async&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Value semantics + managed references&lt;/td&gt;
&lt;td&gt;&lt;em&gt;Structural data races are impossible; deadlocks require deliberate reference cycles&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Clojure's insight, articulated by Rich Hickey in &lt;em&gt;Are We There Yet?&lt;/em&gt; (2009), is that most concurrency bugs are caused by conflating &lt;strong&gt;identity&lt;/strong&gt; (the thing that changes over time) with &lt;strong&gt;state&lt;/strong&gt; (a particular value at a point in time). Once these are separated, most lock-free concurrency becomes trivial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Thread Safety Guarantees: Non-Blocking Reads &amp;amp; Pure Mutations
&lt;/h3&gt;

&lt;p&gt;Clojure achieves architectural thread safety without manual locking mechanisms (&lt;code&gt;synchronized&lt;/code&gt;, mutexes) through explicit guarantees:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutable by Default:&lt;/strong&gt; Persistent collections (&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;vector&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;) use structural sharing. They are inherently thread-safe across any number of concurrent readers without defensive copying.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Blocking Reads:&lt;/strong&gt; Dereferencing a managed reference (&lt;code&gt;@atom&lt;/code&gt;, &lt;code&gt;@ref&lt;/code&gt;, &lt;code&gt;@agent&lt;/code&gt;) is wait-free. Reads never block writes, and writes never block reads. Observers receive an immutable point-in-time snapshot in constant time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure Mutation Functions:&lt;/strong&gt; Because CAS operations (&lt;code&gt;swap!&lt;/code&gt;) and STM transactions (&lt;code&gt;alter&lt;/code&gt;, &lt;code&gt;commute&lt;/code&gt;) automatically retry on contention, state update functions must be pure, side-effect-free calculations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deadlock Elimination:&lt;/strong&gt; Managed reference types remove explicit locking hierarchies, eliminating traditional lock-inversion deadlocks by design.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Atoms: Lock-Free CAS for Independent State
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; An atom wraps a value. Updates are atomic compare-and-swap (CAS).&lt;/span&gt;
&lt;span class="c1"&gt;;; No locks. No synchronized blocks. No deadlocks possible.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;request-counter&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;atom&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:total&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ss"&gt;:errors&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ss"&gt;:in-flight&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;record-request-start!&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;;; swap! applies a pure function to the current value atomically.&lt;/span&gt;
  &lt;span class="c1"&gt;;; If another thread races, swap! retries automatically.&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;swap!&lt;/span&gt; &lt;span class="nv"&gt;request-counter&lt;/span&gt; &lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:in-flight&lt;/span&gt; &lt;span class="nv"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;record-request-end!&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;success?&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;swap!&lt;/span&gt; &lt;span class="nv"&gt;request-counter&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;counters&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;counters&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:total&lt;/span&gt; &lt;span class="nv"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:in-flight&lt;/span&gt; &lt;span class="nv"&gt;dec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;cond-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;not&lt;/span&gt; &lt;span class="nv"&gt;success?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:errors&lt;/span&gt; &lt;span class="nv"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no mutex here. No &lt;code&gt;synchronized&lt;/code&gt;. No possibility of forgetting to unlock under an exception path. The atom guarantees that the update function is applied atomically — retrying automatically on contention — and that all observers see a consistent, immutable snapshot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Software Transactional Memory: Coordinated State Changes
&lt;/h3&gt;

&lt;p&gt;When multiple pieces of state must change together consistently — a bank transfer, a seat reservation, a cache invalidation — Clojure's &lt;code&gt;ref&lt;/code&gt; and &lt;code&gt;dosync&lt;/code&gt; provide Software Transactional Memory (STM):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;account-balances&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ref&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"alice"&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt; &lt;span class="s2"&gt;"bob"&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;transaction-log&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ref&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;transfer!&lt;/span&gt;
  &lt;span class="s2"&gt;"Atomically transfers amount between accounts. Either both changes commit or neither does.
  No locks, no deadlocks, full MVCC isolation."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;from&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dosync&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;from-balance&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;get&lt;/span&gt; &lt;span class="nv"&gt;@account-balances&lt;/span&gt; &lt;span class="nv"&gt;from&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;from-balance&lt;/span&gt; &lt;span class="nv"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ex-info&lt;/span&gt; &lt;span class="s2"&gt;"Insufficient funds"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:from&lt;/span&gt; &lt;span class="nv"&gt;from&lt;/span&gt; &lt;span class="ss"&gt;:balance&lt;/span&gt; &lt;span class="nv"&gt;from-balance&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="c1"&gt;;; Both refs update atomically within this transaction&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alter&lt;/span&gt; &lt;span class="nv"&gt;account-balances&lt;/span&gt; &lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="nv"&gt;from&lt;/span&gt; &lt;span class="nv"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alter&lt;/span&gt; &lt;span class="nv"&gt;account-balances&lt;/span&gt; &lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt;   &lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alter&lt;/span&gt; &lt;span class="nv"&gt;transaction-log&lt;/span&gt; &lt;span class="nv"&gt;conj&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:from&lt;/span&gt; &lt;span class="nv"&gt;from&lt;/span&gt; &lt;span class="ss"&gt;:to&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="ss"&gt;:amount&lt;/span&gt; &lt;span class="nv"&gt;amount&lt;/span&gt;
                                   &lt;span class="ss"&gt;:timestamp&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;java.time.Instant/now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the same semantics as a database transaction — Atomicity, Isolation, Consistency — in application memory, without an external process or network hop.&lt;/p&gt;

&lt;h3&gt;
  
  
  core.async: Communicating Sequential Processes
&lt;/h3&gt;

&lt;p&gt;For streaming pipelines, fan-out architectures, and backpressure-aware queues, &lt;code&gt;core.async&lt;/code&gt; provides Go-style CSP channels on the JVM and in ClojureScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="ss"&gt;'&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;clojure.core.async&lt;/span&gt; &lt;span class="ss"&gt;:refer&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;chan&lt;/span&gt; &lt;span class="nv"&gt;go&lt;/span&gt; &lt;span class="nv"&gt;&amp;lt;!&lt;/span&gt; &lt;span class="nv"&gt;&amp;gt;!&lt;/span&gt; &lt;span class="nv"&gt;close!&lt;/span&gt; &lt;span class="nv"&gt;pipeline-async&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Bounded channel — provides automatic backpressure&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;inference-queue&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;chan&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;results-channel&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;chan&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Process N inferences in parallel, preserving order, with backpressure&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pipeline-async&lt;/span&gt;
  &lt;span class="mi"&gt;8&lt;/span&gt;                   &lt;span class="c1"&gt;;; parallelism&lt;/span&gt;
  &lt;span class="nv"&gt;results-channel&lt;/span&gt;     &lt;span class="c1"&gt;;; output channel&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;request&lt;/span&gt; &lt;span class="nv"&gt;result-ch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="c1"&gt;;; go (not go-loop) — a single async operation: infer, put result, close.&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;go&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;&amp;gt;!&lt;/span&gt; &lt;span class="nv"&gt;result-ch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;llm/infer!&lt;/span&gt; &lt;span class="nv"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;close!&lt;/span&gt; &lt;span class="nv"&gt;result-ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nv"&gt;inference-queue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Critically, &lt;code&gt;core.async&lt;/code&gt; channels work identically in Clojure (JVM) and ClojureScript (browser/Node.js). The same concurrency model — same semantics, same API — operates across your entire full-stack surface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agents and Dynamic Vars: Asynchronous Tasks and Request Tracing
&lt;/h3&gt;

&lt;p&gt;Beyond atoms, refs, and channels, Clojure provides targeted reference primitives for specific concurrency needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;agent&lt;/code&gt; (Asynchronous Updates):&lt;/strong&gt; For uncoordinated, fire-and-forget state mutations and background I/O. Actions dispatched via &lt;code&gt;send&lt;/code&gt; (CPU-bound thread pool) or &lt;code&gt;send-off&lt;/code&gt; (unbounded pool for blocking I/O) process serially per agent without blocking callers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic &lt;code&gt;var&lt;/code&gt; (Thread-Local Context):&lt;/strong&gt; Thread-isolated frame bindings via &lt;code&gt;binding&lt;/code&gt;. This enables explicit context propagation (such as distributed trace IDs, tenant context, and authentication tokens) down the execution stack without polluting function signatures or leaking across threads.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Developer Velocity: The REPL, Zero-Mock TDD, and Generative Testing
&lt;/h2&gt;

&lt;p&gt;The Python data science community popularized the Jupyter notebook as a live, interactive development environment. It was a step forward from edit-compile-run cycles. But notebooks carry well-documented structural problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hidden execution order:&lt;/strong&gt; Cells can be run out of sequence, creating non-reproducible states.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No structural testing:&lt;/strong&gt; Notebooks resist unit testing by design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version control noise:&lt;/strong&gt; JSON-serialized output diffs obscure code changes in pull requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global mutable state:&lt;/strong&gt; Variables persist across cell re-executions unpredictably.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clojure's REPL is a different category of tool. It is not a notebook — it is a &lt;strong&gt;live connection to a running production-equivalent JVM process&lt;/strong&gt;, operated directly from the source file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; In your editor (Emacs, VS Code + Calva, IntelliJ + Cursive):&lt;/span&gt;
&lt;span class="c1"&gt;;; Evaluate this form with Ctrl+Enter — result appears inline in &amp;lt;15ms.&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;analyze-embedding-drift&lt;/span&gt;
  &lt;span class="s2"&gt;"Measures cosine distance between current and baseline embedding distributions."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;current-embeddings&lt;/span&gt; &lt;span class="nv"&gt;baseline-embeddings&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;map&lt;/span&gt; &lt;span class="nv"&gt;vector&lt;/span&gt; &lt;span class="nv"&gt;current-embeddings&lt;/span&gt; &lt;span class="nv"&gt;baseline-embeddings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;map&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;cosine-distance&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;stats/descriptive-summary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Evaluate against live data in the running server — no restart needed:&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;analyze-embedding-drift&lt;/span&gt;
  &lt;span class="nv"&gt;@current-model/embeddings&lt;/span&gt;
  &lt;span class="nv"&gt;@baseline/reference-embeddings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;;; =&amp;gt; {:mean 0.0431, :p95 0.112, :max 0.287, :n 42000}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key distinction: &lt;strong&gt;the REPL evaluates code against the actual running system state.&lt;/strong&gt; You are not simulating; you are inspecting and modifying production-equivalent logic against real data, with real database connections, in the same JVM that serves your HTTP traffic — all while the server continues handling requests.&lt;/p&gt;

&lt;p&gt;This feedback loop collapses the edit → build → restart → verify cycle to under a second.&lt;/p&gt;

&lt;h3&gt;
  
  
  Beyond the REPL: Zero-Mock TDD and Generative Testing
&lt;/h3&gt;

&lt;p&gt;The velocity advantage does not stop at the REPL prompt; it transforms the automated testing discipline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero Mocking Required:&lt;/strong&gt; In traditional enterprise stacks, unit testing domain logic requires extensive mocking frameworks (Mockito, unittest.mock) to isolate classes from complex dependency graphs. In Clojure, business logic is decoupled from managed references and expressed as pure functions over plain data (&lt;code&gt;maps&lt;/code&gt;, &lt;code&gt;vectors&lt;/code&gt;). Tests verify domain logic directly against simple data literals — no mocking, no stubbing, no fragile reflection hacks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generative Property-Based Testing (&lt;code&gt;test.check&lt;/code&gt;):&lt;/strong&gt; While example-based unit tests assert hand-crafted scenarios, &lt;code&gt;test.check&lt;/code&gt; generates hundreds of randomized, structurally valid data inputs against defined invariants. It actively hunts for boundary conditions, edge cases, and arithmetic overflows that human developers routinely miss.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Spike &amp;amp; Shape $\to$ Lock &amp;amp; Verify" Loop:&lt;/strong&gt; Idiomatic Clojure development blends REPL-Driven Development (RDD) with strict Test-Driven Development (TDD). Engineers spike and shape algorithms interactively in the REPL buffer, and once the data shapes stabilize, they formalize the expected contracts into &lt;code&gt;clojure.test&lt;/code&gt; and &lt;code&gt;test.check&lt;/code&gt; property suites. Because the test suite evaluates in an already-running JVM in 5–20ms, the red $\to$ green $\to$ refactor cycle runs continuously without JVM reboot pauses.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Babashka: Clojure at the Command Line
&lt;/h2&gt;

&lt;p&gt;One persistent gap in Clojure's adoption has been scripting and CLI tooling. The JVM's cold-start latency — typically 2 to 5 seconds — made it impractical for shell scripts, CI/CD hooks, and automation pipelines that require fast invocation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Babashka (&lt;code&gt;bb&lt;/code&gt;)&lt;/strong&gt; closes this gap entirely.&lt;/p&gt;

&lt;p&gt;Babashka is a native Clojure interpreter compiled via GraalVM, with a startup time of &lt;strong&gt;under 15 milliseconds&lt;/strong&gt; and an RSS footprint of &lt;strong&gt;15–35MB&lt;/strong&gt;. It includes a curated standard library covering HTTP, JSON, shell execution, file I/O, SQL, and CSV — without any dependency resolution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# No JVM. No dependency download. Starts in &amp;lt;15ms.&lt;/span&gt;
&lt;span class="c"&gt;# cheshire is bundled in Babashka — require it before use.&lt;/span&gt;
bb -e &lt;span class="s1"&gt;'(require (quote [cheshire.core :as json]))
       (-&amp;gt; (slurp "https://api.github.com/repos/babashka/babashka/releases/latest")
           (json/parse-string true)
           :tag_name
           println)'&lt;/span&gt;
&lt;span class="c"&gt;# =&amp;gt; v1.3.191&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="nv"&gt;#!/usr/bin/env&lt;/span&gt; &lt;span class="nv"&gt;bb&lt;/span&gt;
&lt;span class="c1"&gt;;; A complete CI validation script in idiomatic Clojure&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="ss"&gt;'&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;babashka.process&lt;/span&gt; &lt;span class="ss"&gt;:refer&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;shell&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
         &lt;span class="ss"&gt;'&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;clojure.string&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
         &lt;span class="ss"&gt;'&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;cheshire.core&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;json&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;check-service-health&lt;/span&gt;
  &lt;span class="s2"&gt;"Validates that all registered services report healthy status."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;registry-url&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;services&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;slurp&lt;/span&gt; &lt;span class="nv"&gt;registry-url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;json/parse-string&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ss"&gt;:services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;unhealthy&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;remove&lt;/span&gt; &lt;span class="nv"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"healthy"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt; &lt;span class="nv"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;seq&lt;/span&gt; &lt;span class="nv"&gt;unhealthy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;println&lt;/span&gt; &lt;span class="s2"&gt;"UNHEALTHY SERVICES:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;doseq&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;svc&lt;/span&gt; &lt;span class="nv"&gt;unhealthy&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;println&lt;/span&gt; &lt;span class="s2"&gt;" -"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt; &lt;span class="nv"&gt;svc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"→"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt; &lt;span class="nv"&gt;svc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;System/exit&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;println&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;str&lt;/span&gt; &lt;span class="s2"&gt;"All "&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;count&lt;/span&gt; &lt;span class="nv"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;" services healthy."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;check-service-health&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;or&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;*command-line-args*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                          &lt;span class="s2"&gt;"http://localhost:8500/v1/health/services"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a production-grade health check script. It runs in 12ms. It is fully testable — the &lt;code&gt;check-service-health&lt;/code&gt; function takes a URL and returns nothing (exits on failure) — and it is written in the same language as your backend services. Your entire engineering organization shares one language, one set of idioms, and one REPL, from production services to CI scripts to database migrations.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Full-Stack Coherence: ClojureScript + Shadow-CLJS
&lt;/h2&gt;

&lt;p&gt;The conventional full-stack story requires an organization to maintain two distinct languages, two package managers, two module systems, two sets of idioms, and two testing philosophies — typically TypeScript/JavaScript on the frontend and Python, Go, Java, or Rust on the backend.&lt;/p&gt;

&lt;p&gt;ClojureScript with &lt;strong&gt;Shadow-CLJS&lt;/strong&gt; collapses this to a single language across the entire stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; This schema is defined once — shared between backend (Clojure/JVM)&lt;/span&gt;
&lt;span class="c1"&gt;;; and frontend (ClojureScript/Browser) via cljc (platform-agnostic) namespaces.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;app.schema&lt;/span&gt;
  &lt;span class="nv"&gt;#?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:clj&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;malli.core&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="ss"&gt;:cljs&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;malli.core&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;UserProfile&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:map&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user/id&lt;/span&gt;    &lt;span class="ss"&gt;:uuid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user/email&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user/role&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:enum&lt;/span&gt; &lt;span class="ss"&gt;:admin&lt;/span&gt; &lt;span class="ss"&gt;:viewer&lt;/span&gt; &lt;span class="ss"&gt;:editor&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; validate-profile works identically on JVM (API layer) and Browser (form validation)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;validate-profile&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;m/validate&lt;/span&gt; &lt;span class="nv"&gt;UserProfile&lt;/span&gt; &lt;span class="nv"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;:cljc&lt;/code&gt; file extension denotes a &lt;strong&gt;platform-agnostic Clojure namespace&lt;/strong&gt; that compiles to both JVM bytecode and JavaScript. Schema definitions, domain logic, validation rules, and business calculations written once run anywhere.&lt;/p&gt;

&lt;p&gt;Shadow-CLJS provides hot-reload semantics equivalent to Vite or Webpack HMR, with the additional advantage that ClojureScript's immutable data structures make state preservation across hot reloads safe by default — no manual state serialization required.&lt;/p&gt;

&lt;p&gt;For organizations running React-style UIs, &lt;strong&gt;Reagent&lt;/strong&gt; (a React wrapper) and &lt;strong&gt;Re-Frame&lt;/strong&gt; (a Redux-like state machine built on Reagent) provide a battle-tested unidirectional data flow architecture, entirely in ClojureScript, with the same REPL-driven development workflow available on the backend.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Regulatory and Compliance Alignment in 2024–2026
&lt;/h2&gt;

&lt;p&gt;The compliance dimension of this argument is not speculative. It is grounded in active regulatory instruments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory Safety Procurement Requirements
&lt;/h3&gt;

&lt;p&gt;As established in Parts 1 and 2 of this series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;White House ONCD (2024):&lt;/strong&gt; Explicitly names Java/JVM runtimes as approved memory-safe languages alongside Rust, Go, C#, and Swift.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CISA Memory-Safe Roadmaps:&lt;/strong&gt; Requires technology vendors serving public sector contracts to publish migration plans away from memory-unsafe codebases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EU Cyber Resilience Act (CRA):&lt;/strong&gt; Introduces punitive vendor liability for preventable software security flaws — including memory corruption vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Clojure, running on HotSpot JVM or compiled via GraalVM Native Image, satisfies every listed criterion. The 95% attack surface elimination achieved by moving business logic to Clojure, analyzed in Part 2, is directly applicable here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supply Chain Security: The Minimal Dependency Advantage
&lt;/h3&gt;

&lt;p&gt;The EU CRA and the US Executive Order on Improving the Nation's Cybersecurity (EO 14028) both mandate &lt;strong&gt;Software Bill of Materials (SBOM)&lt;/strong&gt; generation and dependency vulnerability tracking.&lt;/p&gt;

&lt;p&gt;A Clojure service's dependency graph — 15 to 40 entries in &lt;code&gt;deps.edn&lt;/code&gt; — is orders of magnitude easier to audit than a 300-dependency Maven or npm graph. &lt;code&gt;clj-holmes&lt;/code&gt;, &lt;code&gt;nvd-clojure&lt;/code&gt;, and &lt;code&gt;deps-audit&lt;/code&gt; provide automated CVE scanning against the full transitive dependency tree. The tool surface is small enough that a security engineer can read every line of &lt;code&gt;deps.edn&lt;/code&gt; in under ten minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Governance: Functional Domain-Driven Design &amp;amp; Immutable Audit Trails
&lt;/h3&gt;

&lt;p&gt;Regulated industries — finance, healthcare, government contracting — require tamper-evident audit logs, strict invariant validation, and reproducible data transformations. Clojure's immutable-first architecture and Functional Domain-Driven Design (FDDD) paradigm provide structural compliance by construction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Decoupled Domain Model:&lt;/strong&gt; Unlike traditional object-oriented DDD where entities encapsulate mutable state behind getter/setter hierarchies, Clojure decouples data, behavior, and identity. Entities and Domain Events are represented by generic immutable maps (e.g., &lt;code&gt;{:event/type :funds/transferred, :tx/id ...}&lt;/code&gt;), Value Objects are native Clojure literals with structural equality (&lt;code&gt;=&lt;/code&gt;), and boundaries are validated declaratively with Malli schemas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aggregate Roots as Pure Reducers:&lt;/strong&gt; In Functional DDD, aggregate business logic is modeled as a pure reducer without side effects or hidden ORM session caches:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;reducer&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="nv"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:keys&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="nv"&gt;events&lt;/span&gt; &lt;span class="nv"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Business invariants are asserted against plain input data, producing a new state and a discrete list of domain event maps. Because the reducer is a pure function, compliance officers and automated auditors can deterministically verify and replay any state transition without spinning up databases or mock fixtures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Every state change is an append-only transaction log entry.&lt;/span&gt;
&lt;span class="c1"&gt;;; No mutation. No overwrite. Full audit trail from day one.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;process-financial-event!&lt;/span&gt;
  &lt;span class="s2"&gt;"Applies an event to the ledger. The old ledger value is never mutated."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ledger-atom&lt;/span&gt; &lt;span class="nv"&gt;event&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;swap!&lt;/span&gt; &lt;span class="nv"&gt;ledger-atom&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ledger&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;ledger&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:entries&lt;/span&gt; &lt;span class="nv"&gt;conj&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;assoc&lt;/span&gt; &lt;span class="nv"&gt;event&lt;/span&gt;
                                            &lt;span class="ss"&gt;:timestamp&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;java.time.Instant/now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                            &lt;span class="ss"&gt;:id&lt;/span&gt;        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;random-uuid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;update&lt;/span&gt; &lt;span class="ss"&gt;:balance&lt;/span&gt; &lt;span class="nv"&gt;apply-event-to-balance&lt;/span&gt; &lt;span class="nv"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Datomic and XTDB — Clojure-native databases — extend this immutability to the persistence layer. Every fact written to Datomic carries a transaction timestamp and is &lt;strong&gt;never overwritten&lt;/strong&gt; — only superseded by new facts. This provides built-in bitemporal audit history with no additional engineering.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. The Skeptic's Corner: Honest Weaknesses
&lt;/h2&gt;

&lt;p&gt;An evidence-based case requires honest accounting of real trade-offs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Talent Pool
&lt;/h3&gt;

&lt;p&gt;Clojure's developer community, while deeply skilled, is significantly smaller than Java, Python, Go, or TypeScript communities. Hiring is harder. The interview funnel for Clojure-specific roles is narrower. Organizations adopting Clojure must invest in internal training or accept that recruiting will take longer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigant:&lt;/strong&gt; Clojure's JVM foundation means Java developers can read and contribute to Clojure codebases with weeks of training rather than months. ClojureScript shares enough semantics with JavaScript that frontend engineers can transition. The language's small core reduces the total learning surface compared to framework-heavy stacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cold-Start Latency on JVM
&lt;/h3&gt;

&lt;p&gt;Standard JVM startup for a Clojure service runs 2–5 seconds. For serverless functions or Lambda invocations where cold-start latency is a P99 metric, this is a material problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigant:&lt;/strong&gt; GraalVM Native Image produces standalone binaries with sub-100ms startup and 30–60MB RSS footprint. Babashka (&amp;lt;15ms) covers all CLI and scripting use cases. For long-running services — the primary Clojure deployment target — startup latency is a one-time cost per deployment, not a recurring performance factor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dynamic Typing in Large Teams
&lt;/h3&gt;

&lt;p&gt;Without compile-time type verification, large codebases can accumulate inconsistent data shapes that surface as runtime errors rather than editor-time warnings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigant:&lt;/strong&gt; Malli and clojure.spec provide runtime schema enforcement at function boundaries. &lt;code&gt;clj-kondo&lt;/code&gt; provides static analysis and type-hint inference that catches the majority of shape mismatches before deployment. The discipline of "data-driven APIs using validated maps" — the dominant Clojure idiom — eliminates most of the class of errors that static types are designed to catch.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory Overhead from Persistent Data Structures
&lt;/h3&gt;

&lt;p&gt;Clojure's immutable persistent collections rely on wide bitmapped vector tries and hash collision trees. While structural sharing prevents full collection copies, each node in the tree is an object with pointer overhead, creating a larger memory footprint and higher GC allocation rates than flat structs, primitive arrays, or raw byte buffers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigant:&lt;/strong&gt; Clojure provides &lt;em&gt;transducers&lt;/em&gt; for composable, zero-allocation intermediate transformations without building intermediate persistent collections. For hot mathematical and I/O kernels, zero-overhead Java interop allows falling back to primitive arrays (&lt;code&gt;double-array&lt;/code&gt;, &lt;code&gt;long-array&lt;/code&gt;) and off-heap direct buffers (&lt;code&gt;ByteBuffer&lt;/code&gt;). Furthermore, modern low-latency JVM garbage collectors (ZGC and Shenandoah) keep GC pauses below one millisecond even under heavy allocation rates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Verbose JVM Stack Traces
&lt;/h3&gt;

&lt;p&gt;When exceptions occur, Clojure's interop layer surfaces full JVM stack traces containing dozens of internal host frames and runtime plumbing (&lt;code&gt;clojure.lang.AFunction&lt;/code&gt;, dynamic call sites). This can be disorienting and intimidating for developers unfamiliar with JVM internals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigant:&lt;/strong&gt; Modern developer tooling dramatically demunges and clarifies stack traces. REPL environments (CIDER, Calva, Cursive) filter out internal JVM frames and highlight user-space code. Libraries like &lt;code&gt;clj-kondo&lt;/code&gt; catch errors at editor time before execution, and diagnostic viewers like &lt;code&gt;portal&lt;/code&gt; provide structured, navigable exception inspections.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Evidence, Assembled
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Engineering Concern (2024–2026)&lt;/th&gt;
&lt;th&gt;Clojure's Structural Advantage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AI pipeline safety&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Immutable values make pipelines pure, testable, and replayable by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;LLM output validation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Malli schemas enforce structural contracts at every inference boundary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Concurrency &amp;amp; Thread Safety&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Non-blocking reads (&lt;code&gt;@&lt;/code&gt;), CAS atoms, STM refs, async agents, CSP channels — data races structurally impossible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Developer iteration speed&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sub-second REPL feedback loop against live running system state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Testing &amp;amp; Quality Assurance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zero-mock testing against pure data functions + generative property-based testing (&lt;code&gt;test.check&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;CLI and automation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Babashka: &amp;lt;15ms startup, 30MB RSS, full Clojure, no JVM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Full-stack coherence&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;ClojureScript + Shadow-CLJS: one language, one schema, one REPL across stack&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory safety compliance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;JVM-class MSL satisfying CISA, ONCD, NSA, and EU CRA mandates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Supply chain auditability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;15–40 direct deps vs 150–300 in Spring/Django; full SBOM in &amp;lt;10 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Regulatory &amp;amp; FDDD Invariants&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Functional DDD (pure aggregate reducers) + Datomic/XTDB = tamper-evident compliance for finance/health/gov&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Framework complexity tax&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~600-function core, composable data-driven libraries (&lt;code&gt;reitit&lt;/code&gt;, &lt;code&gt;next.jdbc&lt;/code&gt;, &lt;code&gt;integrant&lt;/code&gt;) over convention&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Is Clojure the Future Stack?
&lt;/h2&gt;

&lt;p&gt;The honest answer is: it depends on what you are optimizing for.&lt;/p&gt;

&lt;p&gt;If your engineering organization is running Python ML pipelines that are increasingly hard to test and replay, &lt;strong&gt;Clojure's immutable data pipeline model is architecturally superior&lt;/strong&gt; for that workload.&lt;/p&gt;

&lt;p&gt;If you are managing a concurrent service that is hemorrhaging debugging hours on race conditions and mutex complexity, &lt;strong&gt;Clojure's atom/STM/CSP concurrency model eliminates the structural causes of those bugs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you are operating under CISA, CRA, or ONCD compliance requirements and your current stack is C++ or Node.js, &lt;strong&gt;Clojure on JVM satisfies every regulatory criterion&lt;/strong&gt; while delivering more developer velocity than a Rust rewrite.&lt;/p&gt;

&lt;p&gt;If you need a team of three engineers to maintain a backend service, ten CLI automation scripts, two validation pipelines, and a reactive frontend — in one language, with one REPL, with one set of idioms — &lt;strong&gt;Clojure is the only ecosystem that coherently covers that entire surface&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The case is not that Clojure is perfect. The talent pool is real. The JVM cold start is real. The learning curve of parentheses and prefix notation is real.&lt;/p&gt;

&lt;p&gt;The case is that the &lt;strong&gt;design decisions Rich Hickey made in 2007&lt;/strong&gt; — immutability by default, managed concurrency primitives, a live interactive runtime, a small composable core, and a hosted philosophy that embraces the JVM rather than fighting it — &lt;strong&gt;turn out to be precisely correct responses to the engineering problems of 2024–2026&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That is not luck. That is convergent validity.&lt;/p&gt;




&lt;h2&gt;
  
  
  References &amp;amp; Further Reading
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Series Articles
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-economics-of-memory-safety-inaction-vs-the-cost-of-rewriting-43in"&gt;&lt;em&gt;The Economics of Memory Safety: Inaction vs. The Cost of Rewriting&lt;/em&gt; (Part 1)&lt;/a&gt; — Foundational analysis of vulnerability lifecycle costs, regulatory mandates, and C++ limitations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b"&gt;&lt;em&gt;Beyond the Rewrite Trap: High-Velocity Memory Safety with Clojure and Tiered Systems&lt;/em&gt; (Part 2)&lt;/a&gt; — Tiered architecture combining Clojure orchestration with Rust/C++ kernels.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-full-stack-case-for-clojure-ai-concurrency-and-regulatory-reality-4oh4"&gt;&lt;em&gt;The Full-Stack Case for Clojure: AI, Concurrency, and Regulatory Reality&lt;/em&gt; (Part 3)&lt;/a&gt; — Evidence-based case for Clojure across AI pipelines, concurrency, and compliance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Language &amp;amp; Runtime
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Hickey, R. (2009):&lt;/strong&gt; &lt;a href="https://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey/" rel="noopener noreferrer"&gt;&lt;em&gt;Are We There Yet? A Deconstruction of Object-Oriented Time&lt;/em&gt;&lt;/a&gt; — The philosophical foundation of Clojure's identity/state/value model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hickey, R. (2012):&lt;/strong&gt; &lt;a href="https://www.infoq.com/presentations/Value-Values/" rel="noopener noreferrer"&gt;&lt;em&gt;The Value of Values&lt;/em&gt;&lt;/a&gt; — Value semantics vs. place-oriented programming.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenJDK JEP 454 (2024):&lt;/strong&gt; &lt;a href="https://openjdk.org/jeps/454" rel="noopener noreferrer"&gt;&lt;em&gt;Foreign Function &amp;amp; Memory API&lt;/em&gt; (Project Panama)&lt;/a&gt; — Type-safe native memory access on modern JVM.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Tooling
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Babashka:&lt;/strong&gt; &lt;a href="https://babashka.org" rel="noopener noreferrer"&gt;&lt;em&gt;babashka.org&lt;/em&gt;&lt;/a&gt; — Native Clojure scripting runtime with sub-15ms startup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shadow-CLJS:&lt;/strong&gt; &lt;a href="https://shadow-cljs.org" rel="noopener noreferrer"&gt;&lt;em&gt;shadow-cljs.org&lt;/em&gt;&lt;/a&gt; — Full-stack ClojureScript build tooling with npm interop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Malli:&lt;/strong&gt; &lt;a href="https://github.com/metosin/malli" rel="noopener noreferrer"&gt;&lt;em&gt;github.com/metosin/malli&lt;/em&gt;&lt;/a&gt; — Data-driven schema, validation, and coercion for Clojure.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Regulatory
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;White House ONCD (2024):&lt;/strong&gt; &lt;a href="https://bidenwhitehouse.archives.gov/wp-content/uploads/2024/02/Final-ONCD-Technical-Report.pdf" rel="noopener noreferrer"&gt;&lt;em&gt;Back to the Building Blocks&lt;/em&gt;&lt;/a&gt; — Federal guidance designating JVM runtimes as approved memory-safe languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CISA (2023):&lt;/strong&gt; &lt;a href="https://www.cisa.gov/resources-tools/resources/case-memory-safe-roadmaps" rel="noopener noreferrer"&gt;&lt;em&gt;The Case for Memory Safe Roadmaps&lt;/em&gt;&lt;/a&gt; — Procurement directives for technology manufacturers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;European Union (2024):&lt;/strong&gt; &lt;a href="https://digital-strategy.ec.europa.eu/en/policies/cyber-resilience-act" rel="noopener noreferrer"&gt;&lt;em&gt;Cyber Resilience Act (CRA)&lt;/em&gt;&lt;/a&gt; — Vendor liability framework for preventable software security flaws.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>architecture</category>
      <category>ai</category>
      <category>concurrency</category>
    </item>
    <item>
      <title>Clojure for Beginners: Lisp on the JVM, Built for Real Work</title>
      <dc:creator>Arhan Khan</dc:creator>
      <pubDate>Thu, 12 Nov 2026 15:41:23 +0000</pubDate>
      <link>https://dev.to/arhan_khan/clojure-for-beginners-lisp-on-the-jvm-built-for-real-work-3nfd</link>
      <guid>https://dev.to/arhan_khan/clojure-for-beginners-lisp-on-the-jvm-built-for-real-work-3nfd</guid>
      <description>&lt;p&gt;Clojure is a modern Lisp that runs on the JVM. That combination sounds odd until you use it: you get Lisp's simplicity — code is data, functions are values, almost no syntax — with the entire Java ecosystem available when you need it. Clojure is used in production at companies like Nubank and Walmart Labs, mostly for data processing and backend systems.&lt;/p&gt;

&lt;p&gt;Clojure code looks different from what you are used to, and then it stops looking strange:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; double every even number in a list&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;-&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;filter&lt;/span&gt; &lt;span class="nv"&gt;even?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;map&lt;/span&gt; &lt;span class="nv"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;;; (4 8 12)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything is an expression, and data is immutable by default. Instead of changing a value, you create a new one. That sounds slow, but Clojure's persistent data structures share memory cleverly, so it is fast in practice — and it kills a whole category of concurrency bugs, because shared mutable state simply does not exist.&lt;/p&gt;

&lt;p&gt;Clojure is a good fit for backend services, data pipelines, and anything where you transform data. Its REPL-driven workflow is genuinely different: you connect your editor to a running program and evaluate code as you write it, seeing results instantly. Many Clojure developers say this workflow alone is worth learning the language for.&lt;/p&gt;

&lt;p&gt;The limits: Clojure jobs are few, the startup time of the JVM is noticeable, and the Lisp syntax — all those parentheses — takes a week to stop noticing. The library ecosystem is smaller than Java's, and some Java libraries feel awkward from Clojure. Learn it to think differently about state and data, not as a shortcut to a job.&lt;/p&gt;

&lt;p&gt;Start today: install the Clojure CLI, open a REPL, and try the example above. Then build something tiny — a program that reads a CSV file and prints a summary. The moment you refactor without fear because nothing mutates, you will understand why Clojure developers are so loyal to it.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>functional</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Beyond the Rewrite Trap: High-Velocity Memory Safety with Clojure and Tiered Systems</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Tue, 10 Nov 2026 09:59:44 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b</link>
      <guid>https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is **Part 2&lt;/em&gt;* of a 3-part series on &lt;strong&gt;The Economics of Memory Safety&lt;/strong&gt;:*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/the-economics-of-memory-safety-inaction-vs-the-cost-of-rewriting-43in"&gt;Part 1: The Economics of Memory Safety — Inaction vs. The Cost of Rewriting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2: Beyond the Rewrite Trap — High-Velocity Memory Safety with Clojure and Tiered Systems&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ganesh_rajendran_art/the-full-stack-case-for-clojure-ai-concurrency-and-regulatory-reality-4oh4"&gt;Part 3: The Full-Stack Case for Clojure — AI, Concurrency, and Regulatory Reality&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;




&lt;p&gt;In &lt;a href="https://dev.to/ganesh_rajendran_art/the-economics-of-memory-safety-inaction-vs-the-cost-of-rewriting-43in"&gt;&lt;em&gt;The Economics of Memory Safety: Inaction vs. The Cost of Rewriting&lt;/em&gt;&lt;/a&gt;, we examined the financial and regulatory forces reshaping software engineering. Decades of telemetry from Microsoft, Google, and Apple confirmed that &lt;strong&gt;~70% of all high-severity vulnerabilities are memory safety flaws&lt;/strong&gt;, irrespective of modern C++ language revisions (&lt;code&gt;C++11&lt;/code&gt; through &lt;code&gt;C++23&lt;/code&gt;). Concurrently, procurement mandates from CISA, the White House Office of the National Cyber Director (ONCD), and the EU Cyber Resilience Act (CRA) have transformed memory safety from an abstract hygiene debate into an urgent balance sheet imperative.&lt;/p&gt;

&lt;p&gt;Yet for engineering organizations managing multi-million-line C++ codebases, the standard prescription—&lt;em&gt;"just rewrite everything in Rust"&lt;/em&gt;—presents a dangerous trap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The High-CapEx Trap:&lt;/strong&gt; Multi-year feature freezes, astronomical developer retraining costs, and lost market opportunities while teams struggle with compiler borrow checkers to achieve feature parity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Second-System Effect:&lt;/strong&gt; Subtle edge-case domain knowledge accumulated over decades of C++ production fixes is discarded during clean-slate rebuilds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Must engineering teams choose between the perpetual vulnerability tax of C++ and the organizational friction and multi-year delays of a monolithic Rust rewrite?&lt;/p&gt;

&lt;p&gt;There is a superior alternative: &lt;strong&gt;The Tiered Systems Architecture&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;By pairing &lt;strong&gt;Clojure&lt;/strong&gt; as the high-level domain, state, and concurrency orchestrator with &lt;strong&gt;confined Rust or hardened C++ kernels&lt;/strong&gt; at the performance boundary, organizations can eliminate 100% of memory safety vulnerabilities across their attack surface while &lt;em&gt;increasing&lt;/em&gt; feature delivery velocity.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Anatomy of the Tiered Systems Architecture
&lt;/h2&gt;

&lt;p&gt;The fundamental error of monolithic rewrites is treating all code as if it has the same operational constraints. &lt;/p&gt;

&lt;p&gt;In a typical production backend, less than &lt;strong&gt;5% of the codebase&lt;/strong&gt; is genuinely hardware-bound (e.g., tight vectorization loops, cryptographic ciphers, audio/video codecs, or network packet serialization). The remaining &lt;strong&gt;95%&lt;/strong&gt; consists of business workflows, API routing, untrusted payload parsing, validation, state machines, database coordination, and concurrency orchestration.&lt;/p&gt;

&lt;p&gt;Forcing that 95% into a low-level systems language with manual lifetime annotations imposes immense cognitive drag without adding security value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+-----------------------------------------------------------------------------+
|                          CLOJURE TIER (Safe Domain)                         |
|  * Persistent Immutable Data Structures (HAMTs)                             |
|  * Explicit State Primitives (Atoms with CAS, Refs with MVCC/STM)           |
|  * Automated Tracing Garbage Collection (ZGC, G1, Substrate VM)             |
|  * Sub-Second REPL Feedback Loop &amp;amp; Dynamic Schema Validation                |
|  * Immune to: UAF, Buffer Overflows, Double Free, Data Races                |
+-----------------------------------------------------------------------------+
                                      |
                     [ Strictly Bound Foreign Interface ]
                     * HotSpot JVM: Project Panama Scoped Arenas
                     * GraalVM Native: Isolated C Entrypoints
                     * ClojureScript: Sandboxed Wasm Linear Memory
                                      v
+-----------------------------------------------------------------------------+
|                     SYSTEMS KERNEL TIER (Performance Core)                  |
|  * Confined Rust or Hardened C++ Routines (SIMD, DSP, Codecs, Drivers)      |
|  * Zero-Copy Slices with Explicit Length Metadata                           |
|  * Narrow Attack Surface &amp;amp; Fully Deterministic Deallocation                 |
+-----------------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Division of Responsibilities
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Safe Orchestrator (Clojure):&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Manages domain entities using persistent immutable structures (Hash Array Mapped Tries).&lt;/li&gt;
&lt;li&gt;Ingests external network payloads, validating schemas via runtime contracts (&lt;code&gt;malli&lt;/code&gt; / &lt;code&gt;clojure.spec&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Eliminates concurrency data races by separating identity from state using software transactional memory (&lt;code&gt;ref&lt;/code&gt;) and atomic reference cells (&lt;code&gt;atom&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Systems Kernel (Rust / C++):&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Confined to isolated, stateless, high-throughput compute routines.&lt;/li&gt;
&lt;li&gt;Interfaced through modern, zero-overhead Foreign Function Interfaces (FFI).&lt;/li&gt;
&lt;li&gt;Communicates via explicit memory buffers with strict boundary descriptors, preventing memory corruption bugs from escaping into the application runtime.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  2. How Clojure Eliminates the 13 C++ Hazards Without Lifetimes
&lt;/h2&gt;

&lt;p&gt;Modern C++ attempted to solve memory safety through convention (RAII, &lt;code&gt;std::unique_ptr&lt;/code&gt;, &lt;code&gt;std::span&lt;/code&gt;, &lt;code&gt;std::string_view&lt;/code&gt;). As demonstrated across industry vulnerability taxonomies, these conventions fail in practice because C++ remains &lt;strong&gt;unsafe by default&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Rust resolved this by introducing compile-time affine type systems and a borrow checker. However, this introduces substantial developer friction—especially when modeling graph-like business topologies, cache structures, or asynchronous event pipelines.&lt;/p&gt;

&lt;p&gt;Clojure achieves identical safety through a fundamentally different mathematical foundation: &lt;strong&gt;value semantics and managed runtimes&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Hazard Category&lt;/th&gt;
&lt;th&gt;Specific C++ Hazard&lt;/th&gt;
&lt;th&gt;Rust Solution&lt;/th&gt;
&lt;th&gt;Clojure Solution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Spatial&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Buffer Overflows (Heap/Stack)&lt;/td&gt;
&lt;td&gt;Bounds check / Slices&lt;/td&gt;
&lt;td&gt;Checked indices / &lt;code&gt;ISeq&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Spatial&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Pointer Arithmetic Overrun&lt;/td&gt;
&lt;td&gt;Unsafe blocks required&lt;/td&gt;
&lt;td&gt;No pointer arithmetic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Spatial&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Off-by-One / Null-Terminators&lt;/td&gt;
&lt;td&gt;UTF-8 slice lengths&lt;/td&gt;
&lt;td&gt;Immutable String types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temporal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Use-After-Free (UAF)&lt;/td&gt;
&lt;td&gt;Compile-time borrow check&lt;/td&gt;
&lt;td&gt;Tracing Garbage Collector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temporal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Double Free&lt;/td&gt;
&lt;td&gt;Affine types / Drop&lt;/td&gt;
&lt;td&gt;Automated GC deallocation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temporal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dangling Stack References&lt;/td&gt;
&lt;td&gt;Lifetime bounds (&lt;code&gt;'a&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Escape analysis / Heap allocation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temporal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Iterator Invalidation&lt;/td&gt;
&lt;td&gt;Exclusive borrow (&lt;code&gt;&amp;amp;mut&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Persistent data structures (HAMT)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temporal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lambda Capture Invalidation&lt;/td&gt;
&lt;td&gt;Move closures&lt;/td&gt;
&lt;td&gt;Value-capture semantics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Initialization&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uninitialized Memory Read&lt;/td&gt;
&lt;td&gt;Definite initialization&lt;/td&gt;
&lt;td&gt;Safe default / &lt;code&gt;nil&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Type Confusion / Downcasting&lt;/td&gt;
&lt;td&gt;Safe enums / Traits&lt;/td&gt;
&lt;td&gt;Strict runtime dynamic checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Untagged Union Misuse&lt;/td&gt;
&lt;td&gt;Exhaustive matching&lt;/td&gt;
&lt;td&gt;Tagged maps / Multimethods&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Concurrency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data Races (Undefined State)&lt;/td&gt;
&lt;td&gt;Send / Sync traits&lt;/td&gt;
&lt;td&gt;Value immutability + CAS primitives&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Resource&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Memory Leaks (Cyclic)&lt;/td&gt;
&lt;td&gt;Weak refs / Box trees&lt;/td&gt;
&lt;td&gt;Tracing cycle collectors&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Why Value Semantics Beat Borrow Checking for Domain Logic
&lt;/h3&gt;

&lt;p&gt;Consider the &lt;strong&gt;Iterator Invalidation&lt;/strong&gt; problem in C++. Modifying a &lt;code&gt;std::vector&lt;/code&gt; while iterating over it triggers reallocation, invalidating active pointers and causing undefined behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// C++: Catastrophic Iterator Invalidation&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// UB: Reallocation invalidates 'it'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Rust, the borrow checker prevents this at compile time by prohibiting simultaneous mutable and immutable borrows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Rust: Compile error prevents corruption, but requires architectural restructuring&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Error: cannot borrow `numbers` as mutable because it is also borrowed as immutable&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Clojure, this class of bugs is &lt;strong&gt;mathematically impossible&lt;/strong&gt;. Data structures are persistent and immutable. Modifying a collection yields a new version that shares structure with the old one, leaving all existing references intact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Clojure: Pure value evolution. No invalidation, no lifetimes, zero lock overhead.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="c1"&gt;;; Thread A can iterate indefinitely across its immutable snapshot:&lt;/span&gt;
      &lt;span class="nv"&gt;_&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;doseq&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;println&lt;/span&gt; &lt;span class="s2"&gt;"Processing:"&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="c1"&gt;;; Thread B evolves state without mutating Thread A's data:&lt;/span&gt;
      &lt;span class="nv"&gt;updated-numbers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;conj&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:original&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="ss"&gt;:updated&lt;/span&gt; &lt;span class="nv"&gt;updated-numbers&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither thread can corrupt memory, cause a use-after-free, or trigger a data race.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Polyglot Boundary Safety: Multi-Target FFI Engineering
&lt;/h2&gt;

&lt;p&gt;A common objection to hybrid architectures is: &lt;em&gt;"Doesn't crossing the FFI boundary reintroduce memory safety vulnerabilities?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Historically, legacy JNI (Java Native Interface) was prone to memory leaks and invalid pointer dereferences. Today, the Clojure runtime landscape provides three battle-tested targets with hardened boundary abstractions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Target 1: HotSpot JVM + Project Panama Scoped Arenas (JDK 22+)
&lt;/h3&gt;

&lt;p&gt;Project Panama replaces legacy JNI with type-safe foreign memory access. By leveraging &lt;code&gt;Arena.ofConfined()&lt;/code&gt; within Clojure's &lt;code&gt;with-open&lt;/code&gt;, off-heap native memory is bound to a deterministic lexical scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;safety.panama-demo&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:import&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;java.lang.foreign&lt;/span&gt; &lt;span class="nv"&gt;Arena&lt;/span&gt; &lt;span class="nv"&gt;MemorySegment&lt;/span&gt; &lt;span class="nv"&gt;ValueLayout&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;process-native-telemetry&lt;/span&gt;
  &lt;span class="s2"&gt;"Allocates off-heap native memory for a hardware kernel, guarantees spatial
   bounds enforcement, and deterministically frees memory upon exit."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;^long&lt;/span&gt; &lt;span class="nv"&gt;record-count&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;byte-size&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;record-count&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;with-open&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;arena&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Arena/ofConfined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="c1"&gt;;; Allocate off-heap memory bounded strictly to this lexical block&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;^MemorySegment&lt;/span&gt; &lt;span class="nv"&gt;segment&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.allocate&lt;/span&gt; &lt;span class="nv"&gt;arena&lt;/span&gt; &lt;span class="nv"&gt;byte-size&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

        &lt;span class="c1"&gt;;; Spatial Safety: Attempting to write past byte-size throws IndexOutOfBoundsException&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.setAtIndex&lt;/span&gt; &lt;span class="nv"&gt;segment&lt;/span&gt; &lt;span class="nv"&gt;ValueLayout/JAVA_LONG&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1002043&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;;; Safely invoke native Rust / C++ kernel via MethodHandle...&lt;/span&gt;
        &lt;span class="c1"&gt;;; (.invokeExact ^MethodHandle native-filter-fn segment record-count)&lt;/span&gt;

        &lt;span class="c1"&gt;;; Read back processed result&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt; &lt;span class="ss"&gt;:ok&lt;/span&gt; 
         &lt;span class="ss"&gt;:head&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.getAtIndex&lt;/span&gt; &lt;span class="nv"&gt;segment&lt;/span&gt; &lt;span class="nv"&gt;ValueLayout/JAVA_LONG&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;;; CRITICAL: Outside 'with-open', the arena is closed.&lt;/span&gt;
&lt;span class="c1"&gt;;; Any subsequent access to 'segment' immediately throws IllegalStateException.&lt;/span&gt;
&lt;span class="c1"&gt;;; Use-After-Free is structurally prevented!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Target 2: GraalVM Native Image &amp;amp; Babashka: Low-Footprint Standalone Binaries
&lt;/h3&gt;

&lt;p&gt;For CLI tools, serverless functions, or container sidecars where JVM warm-up or memory footprint is prohibitive, Clojure provides two distinct native execution models:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. GraalVM Native Image (AOT Compilation &amp;amp; C ABI Export)
&lt;/h4&gt;

&lt;p&gt;Clojure compiles Ahead-of-Time (AOT) to standalone native binaries using GraalVM Substrate VM. Using &lt;code&gt;@CEntryPoint&lt;/code&gt;, Clojure logic is exposed directly over the standard C ABI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Java/Clojure bridge compiled into GraalVM native shared library (.so / .dylib)&lt;/span&gt;
&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;safety&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nativebridge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graalvm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nativeimage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CEntryPoint&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graalvm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nativeimage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CCharPointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graalvm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nativeimage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CTypeConversion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SafeGateway&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@CEntryPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gateway_process_packet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;processPacket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CEntryPoint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsolateThread&lt;/span&gt; &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                                    &lt;span class="nc"&gt;CCharPointer&lt;/span&gt; &lt;span class="n"&gt;rawBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                                    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Strict boundary defense: validate native inputs before domain handoff&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawBytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Convert to immutable managed string inside isolated runtime heap&lt;/span&gt;
        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CTypeConversion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toJavaString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graalvm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WordFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsigned&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Dispatch to Clojure domain engine (registered in reflect-config.json)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;clojure&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;RT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"service.ingress"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"handle-packet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Babashka Dynamic FFI (Instant Execution &amp;amp; Native Binding)
&lt;/h4&gt;

&lt;p&gt;For automated pipelines and CLI tooling, &lt;strong&gt;Babashka (&lt;code&gt;bb&lt;/code&gt;)&lt;/strong&gt; starts in &lt;strong&gt;&amp;lt; 15 milliseconds&lt;/strong&gt; with an &lt;strong&gt;RSS footprint of ~15MB to ~35MB&lt;/strong&gt;. Rather than compiling Java bridges, Babashka bundles &lt;code&gt;libffi&lt;/code&gt; via &lt;code&gt;babashka.ffi&lt;/code&gt;, loading native shared libraries directly from scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; In Babashka: Load C/Rust shared libraries dynamically without compilation&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="ss"&gt;'&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;babashka.ffi&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;lib&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ffi/load-library&lt;/span&gt; &lt;span class="s2"&gt;"./target/release/libkernel.so"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;compute-fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ffi/cfn&lt;/span&gt; &lt;span class="nv"&gt;lib&lt;/span&gt; &lt;span class="s2"&gt;"compute_hash"&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:pointer&lt;/span&gt; &lt;span class="ss"&gt;:int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ss"&gt;:long&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;;; Pass memory buffers safely to native code with dynamic type coercion&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;compute-fn&lt;/span&gt; &lt;span class="nv"&gt;raw-buffer-ptr&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;count&lt;/span&gt; &lt;span class="nv"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Target 3: ClojureScript &amp;amp; WebAssembly: Hardware-Isolated Sandboxes
&lt;/h3&gt;

&lt;p&gt;In edge computing or browser runtimes, ClojureScript interfaces with Rust/C++ kernels compiled to WebAssembly. &lt;/p&gt;

&lt;p&gt;Because WebAssembly runs within a strictly isolated linear memory buffer (&lt;code&gt;ArrayBuffer&lt;/code&gt;), even an internal buffer overflow or use-after-free within the C++/Rust code &lt;strong&gt;cannot escape its sandbox or corrupt the host runtime&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;safety.wasm-interop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;run-sandboxed-kernel&lt;/span&gt;
  &lt;span class="s2"&gt;"Executes a compiled C++/Rust kernel inside WebAssembly linear memory.
   Memory corruption inside the kernel is isolated from the host environment."&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;^js&lt;/span&gt; &lt;span class="nv"&gt;wasm-instance&lt;/span&gt; &lt;span class="nv"&gt;^js&lt;/span&gt; &lt;span class="nv"&gt;raw-payload&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;memory&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-memory&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-exports&lt;/span&gt; &lt;span class="nv"&gt;wasm-instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;length&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-length&lt;/span&gt; &lt;span class="nv"&gt;raw-payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;;; Allocate space inside Wasm linear memory&lt;/span&gt;
        &lt;span class="nv"&gt;offset&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.malloc&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-exports&lt;/span&gt; &lt;span class="nv"&gt;wasm-instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;;; Create a bounded typed view into Wasm memory&lt;/span&gt;
        &lt;span class="nv"&gt;wasm-view&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;js/Uint8Array.&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-buffer&lt;/span&gt; &lt;span class="nv"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;offset&lt;/span&gt; &lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="c1"&gt;;; Transfer data to sandbox&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.set&lt;/span&gt; &lt;span class="nv"&gt;wasm-view&lt;/span&gt; &lt;span class="nv"&gt;raw-payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;;; Execute native code: Even a crash or overflow is trapped inside Wasm!&lt;/span&gt;
    &lt;span class="c1"&gt;;; Note: If the kernel triggers memory.grow, the old ArrayBuffer cleanly detaches,&lt;/span&gt;
    &lt;span class="c1"&gt;;; raising a safe JavaScript TypeError rather than accessing corrupted heap.&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;exit-code&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.process_frame&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-exports&lt;/span&gt; &lt;span class="nv"&gt;wasm-instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;offset&lt;/span&gt; &lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.free&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.-exports&lt;/span&gt; &lt;span class="nv"&gt;wasm-instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;zero?&lt;/span&gt; &lt;span class="nv"&gt;exit-code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ss"&gt;:success&lt;/span&gt; &lt;span class="ss"&gt;:kernel-error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Addressing the Systems Objections (The Skeptic's Corner)
&lt;/h2&gt;

&lt;p&gt;Whenever a managed language like Clojure is proposed to modernize a C++ codebase, systems engineers raise predictable objections. Let's dismantle them with empirical realities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objection 1: "Garbage collection causes unpredictable latency and stop-the-world pauses."
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Reality:&lt;/strong&gt; The narrative that GC runtimes cause massive freezes is stuck in 2008. &lt;/li&gt;
&lt;li&gt;Modern generational collectors on HotSpot—specifically &lt;strong&gt;ZGC&lt;/strong&gt; and &lt;strong&gt;Shenandoah&lt;/strong&gt;—guarantee maximum GC pause times of &lt;strong&gt;under 1 millisecond&lt;/strong&gt;, even on heaps scaling to multiple terabytes.&lt;/li&gt;
&lt;li&gt;For resource-constrained or CLI targets, &lt;strong&gt;GraalVM Native Image&lt;/strong&gt; and &lt;strong&gt;Babashka&lt;/strong&gt; embed lightweight, deterministic collectors with sub-millisecond cycles and RSS footprints under 30MB.&lt;/li&gt;
&lt;li&gt;Unless you are writing hard real-time avionics or high-frequency trading matching engines running directly on NICs, modern GC latency is an order of magnitude lower than your network round-trip time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Objection 2: "Dynamic typing compromises safety and causes production crashes."
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Reality:&lt;/strong&gt; Dynamic typing is not weak typing. Clojure is strongly typed; arbitrary pointer typecasting (&lt;code&gt;reinterpret_cast&lt;/code&gt;) is impossible.&lt;/li&gt;
&lt;li&gt;In systems development, most fatal bugs are not type mismatches—they are &lt;strong&gt;state synchronization and memory lifecycle errors&lt;/strong&gt;. Clojure’s immutable values and transactional references completely eliminate that entire class of bugs.&lt;/li&gt;
&lt;li&gt;At ingress boundaries, Clojure utilizes libraries like &lt;code&gt;malli&lt;/code&gt; or &lt;code&gt;clojure.spec&lt;/code&gt; to validate payload contracts with expressive structural constraints that static type checkers struggle to represent:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Explicit boundary contract: runtime-verified, zero memory risk&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;OrderPayload&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:map&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:order/id&lt;/span&gt; &lt;span class="ss"&gt;:uuid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:order/amount&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ss"&gt;:max&lt;/span&gt; &lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:order/items&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:vector&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:min&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Objection 3: "Only Rust is endorsed by regulatory agencies like CISA and the White House."
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Reality:&lt;/strong&gt; This is factually incorrect.&lt;/li&gt;
&lt;li&gt;The White House ONCD report (&lt;em&gt;Back to the Building Blocks&lt;/em&gt;), the NSA &lt;em&gt;Software Memory Safety Guidance&lt;/em&gt;, and CISA &lt;em&gt;Memory Safe Roadmaps&lt;/em&gt; explicitly designate the entire class of &lt;strong&gt;Memory-Safe Languages (MSLs)&lt;/strong&gt;, specifically citing Java/JVM runtimes, C#, Go, Rust, and Swift.&lt;/li&gt;
&lt;li&gt;Clojure, running on the battle-tested JVM or compiled via GraalVM, satisfies every enterprise regulatory mandate for memory-safe software procurement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Objection 4: "HAMT persistent collections cause pointer chasing and destroy L1/L2 cache locality."
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Reality:&lt;/strong&gt; For tight numeric matrix multiplication, cryptography, or SIMD vectorization, contiguous memory (&lt;code&gt;std::vector&lt;/code&gt; or Rust &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;/code&gt;) is unquestionably superior.&lt;/li&gt;
&lt;li&gt;However, 95% of application code is bound by network serialization, database transactions, and business logic validation—not L1 cache misses.&lt;/li&gt;
&lt;li&gt;In the Tiered Architecture, cache-sensitive numeric buffers remain in contiguous native memory segments via Project Panama or Rust kernels. Clojure uses persistent HAMTs for application-level state where structural sharing, immutability, and zero-lock concurrency vastly outweigh cache-line packing.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Executive ROI &amp;amp; Regulatory Compliance Checklist
&lt;/h2&gt;

&lt;p&gt;For VP of Engineering, CTOs, and Principal Architects managing legacy C++ estates, the table below provides an executive evaluation framework:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Evaluation Dimension&lt;/th&gt;
&lt;th&gt;Legacy C++&lt;/th&gt;
&lt;th&gt;Monolithic Rust Rewrite&lt;/th&gt;
&lt;th&gt;Tiered Architecture (Clojure + Rust)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Capital Expenditure (CapEx)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Low upfront, massive tail&lt;/td&gt;
&lt;td&gt;Extremely High ($3M–$10M+)&lt;/td&gt;
&lt;td&gt;Moderate ($300k–$800k)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Product Feature Freeze&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None (Slowed by triage)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;18–36 Months&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Zero&lt;/strong&gt; (Iterative boundary refactoring)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Developer Velocity&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Low (steep compiler curve)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Very High&lt;/strong&gt; (Live REPL, instant feedback)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory Safety Coverage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~30% (70% CVE vulnerability)&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;95–98%&lt;/strong&gt; (Confined native boundaries)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Regulatory Risk (CISA/CRA)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Critical Exposure&lt;/td&gt;
&lt;td&gt;Fully Compliant&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Fully Compliant&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mean Time to Remediate (MTTR)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Days to Weeks&lt;/td&gt;
&lt;td&gt;Hours&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Minutes&lt;/strong&gt; (Hot code reloading via REPL)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The Executive Memory Safety Checklist
&lt;/h3&gt;

&lt;p&gt;Before committing your organization to a high-risk multi-year rewrite, conduct this architectural review:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] &lt;strong&gt;Audit the Attack Surface:&lt;/strong&gt; Identify modules directly exposed to untrusted inputs (public HTTP endpoints, file decoders, network packet ingresses). &lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Enforce the Ingress Boundary Rule:&lt;/strong&gt; Mandate that all &lt;em&gt;new&lt;/em&gt; ingress endpoints and deserializers be implemented in Clojure or an MSL. Never expose raw C++ memory to external network sockets.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Decouple State from Compute:&lt;/strong&gt; Identify code sections managing business state versus raw computation. Move application state machines to Clojure &lt;code&gt;atom&lt;/code&gt; and persistent collections.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Adopt Modern FFI Tooling:&lt;/strong&gt; Retire legacy JNI glue in favor of Project Panama (&lt;code&gt;java.lang.foreign&lt;/code&gt;) scoped arenas to guarantee deterministic off-heap lifetimes.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Draft the Memory Safe Roadmap:&lt;/strong&gt; Publish an architectural migration plan documenting your tiered strategy to preserve eligibility for public sector contracts and satisfy EU CRA compliance.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Memory safety is not a moral issue or a binary language contest—it is an exercise in &lt;strong&gt;risk management and engineering economics&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Monolithic rewrites often sacrifice organizational agility in pursuit of ideological purity. By adopting a &lt;strong&gt;Tiered Systems Architecture&lt;/strong&gt;—anchoring business logic, concurrency, and ingress orchestration in &lt;strong&gt;Clojure&lt;/strong&gt;, while confining &lt;strong&gt;Rust or C++&lt;/strong&gt; strictly to hardware-accelerated kernels—engineering organizations eliminate their vulnerability footprint, insulate their balance sheets from regulatory penalties, and maintain an unshakeable competitive advantage in shipping velocity.&lt;/p&gt;




&lt;h2&gt;
  
  
  References &amp;amp; Further Reading
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Regulatory &amp;amp; Institutional Mandates
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;CISA, NSA, FBI, and International Partners (2023):&lt;/strong&gt; &lt;a href="https://www.cisa.gov/resources-tools/resources/case-memory-safe-roadmaps" rel="noopener noreferrer"&gt;&lt;em&gt;The Case for Memory Safe Roadmaps&lt;/em&gt;&lt;/a&gt; — Directives for technology manufacturers to eliminate non-memory-safe codebases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;White House Office of the National Cyber Director (ONCD) (2024):&lt;/strong&gt; &lt;a href="https://bidenwhitehouse.archives.gov/wp-content/uploads/2024/02/Final-ONCD-Technical-Report.pdf" rel="noopener noreferrer"&gt;&lt;em&gt;Back to the Building Blocks: A Path Toward Secure and Measurable Software&lt;/em&gt;&lt;/a&gt; — Federal guidance designating memory-safe programming languages for critical infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;European Union (2024):&lt;/strong&gt; &lt;a href="https://digital-strategy.ec.europa.eu/en/policies/cyber-resilience-act" rel="noopener noreferrer"&gt;&lt;em&gt;Cyber Resilience Act (CRA)&lt;/em&gt;&lt;/a&gt; — Regulatory framework establishing strict vendor liability for preventable software security flaws.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft Security Response Center (MSRC) (2019–2023):&lt;/strong&gt; &lt;a href="https://msrc.microsoft.com/blog/2019/07/a-proactive-approach-to-more-secure-code/" rel="noopener noreferrer"&gt;&lt;em&gt;A Proactive Approach to More Secure Code&lt;/em&gt;&lt;/a&gt; — Empirical telemetry documenting that ~70% of historical CVEs stem from memory corruption.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Technical Specifications &amp;amp; Architecture
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;OpenJDK JEP 454 (2024):&lt;/strong&gt; &lt;a href="https://openjdk.org/jeps/454" rel="noopener noreferrer"&gt;&lt;em&gt;Foreign Function &amp;amp; Memory API&lt;/em&gt; (Project Panama)&lt;/a&gt; — Deterministic, type-safe off-heap native memory allocation and scoped arena lifecycles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GraalVM Community (2024):&lt;/strong&gt; &lt;a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/build-native-shared-library/" rel="noopener noreferrer"&gt;&lt;em&gt;GraalVM Native Image C Interoperability &amp;amp; Substrate VM&lt;/em&gt;&lt;/a&gt; — Ahead-of-time compilation of managed runtimes into standalone native binaries with embedded garbage collection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bagwell, P. &amp;amp; Hickey, R. (2001, 2008):&lt;/strong&gt; &lt;a href="https://lampwww.epfl.ch/papers/idealhashtrees.pdf" rel="noopener noreferrer"&gt;&lt;em&gt;Ideal Hash Trees&lt;/em&gt; and &lt;em&gt;Persistent Data Structures&lt;/em&gt;&lt;/a&gt; — Foundations of Clojure's lock-free, structurally shared immutable collections (HAMTs).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Series Articles
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-economics-of-memory-safety-inaction-vs-the-cost-of-rewriting-43in"&gt;&lt;em&gt;The Economics of Memory Safety: Inaction vs. The Cost of Rewriting&lt;/em&gt; (Part 1)&lt;/a&gt; — Foundational analysis of vulnerability lifecycle costs, regulatory mandates, and modern C++ limitations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/beyond-the-rewrite-trap-high-velocity-memory-safety-with-clojure-and-tiered-systems-2m9b"&gt;&lt;em&gt;Beyond the Rewrite Trap: High-Velocity Memory Safety with Clojure and Tiered Systems&lt;/em&gt; (Part 2)&lt;/a&gt; — Tiered architecture combining Clojure orchestration with Rust/C++ kernels.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rajendran, G. (2026):&lt;/strong&gt; &lt;a href="https://dev.to/ganesh_rajendran_art/the-full-stack-case-for-clojure-ai-concurrency-and-regulatory-reality-4oh4"&gt;&lt;em&gt;The Full-Stack Case for Clojure: AI, Concurrency, and Regulatory Reality&lt;/em&gt; (Part 3)&lt;/a&gt; — Evidence-based case for Clojure across AI pipelines, concurrency, and compliance.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>rust</category>
      <category>cpp</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Proving What AI Generates: Running Formally Verified Lean 4 Inside Clojure Services</title>
      <dc:creator>Ganesh Rajendran</dc:creator>
      <pubDate>Fri, 06 Nov 2026 04:52:16 +0000</pubDate>
      <link>https://dev.to/ganesh_rajendran_art/proving-what-ai-generates-running-formally-verified-lean-4-inside-clojure-services-3hip</link>
      <guid>https://dev.to/ganesh_rajendran_art/proving-what-ai-generates-running-formally-verified-lean-4-inside-clojure-services-3hip</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unit tests only check sample points; formal verification in &lt;strong&gt;Lean 4&lt;/strong&gt; mathematically guarantees logic for &lt;em&gt;all&lt;/em&gt; inputs.&lt;/li&gt;
&lt;li&gt;The new &lt;strong&gt;Ansatz Lean/JVM SDK (&lt;code&gt;org.replikativ/ansatz-lean-jvm:0.2.615&lt;/code&gt;)&lt;/strong&gt; lets you compile Lean into an intermediate artifact (&lt;code&gt;.leanjvm&lt;/code&gt;) and interpret it directly on standard OpenJDK 17+ with zero native C/JNI dependencies.&lt;/li&gt;
&lt;li&gt;This article demonstrates how an AI coding agent can write financial ledger invariants, self-correct via Lean compiler proofs, and deploy proved code into a Clojure service.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;Credit &amp;amp; Attribution: This workflow builds on the breakthrough work by the Simmis team introducing the &lt;a href="https://simm.is/blog/lean-on-the-jvm/" rel="noopener noreferrer"&gt;Ansatz Lean/JVM SDK&lt;/a&gt; (&lt;code&gt;org.replikativ/ansatz-lean-jvm&lt;/code&gt;). The financial settlement walkthrough below illustrates these mechanics applied to autonomous agent engineering.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The LLM Reliability Wall in Production
&lt;/h2&gt;

&lt;p&gt;Every engineering team deploying autonomous AI coding agents eventually runs into the &lt;strong&gt;LLM Reliability Wall&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An agent prompted to generate an account transfer or settlement routine writes clean code in seconds. It even produces dozens of passing unit tests. But unit tests only sample finite scenarios. In financial ledgers, the bug that triggers insolvency is never the one tested by a handful of mock transactions—it lurks in the untested corner case where an overdraft limit, a currency conversion edge, and a zero-sum constraint collide.&lt;/p&gt;

&lt;p&gt;For decades, formal methods offered the mathematical antidote: &lt;strong&gt;prove&lt;/strong&gt; that code satisfies invariants for &lt;em&gt;all&lt;/em&gt; possible inputs using proof assistants like &lt;a href="https://lean-lang.org/" rel="noopener noreferrer"&gt;Lean 4&lt;/a&gt;. But Lean code was traditionally an island:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Native binaries required brittle JNI or Panama bridges.&lt;/li&gt;
&lt;li&gt;Memory models clashed: Lean frees memory via reference counting, while the JVM uses a garbage collector. Cycles across the boundary leak memory.&lt;/li&gt;
&lt;li&gt;Deployed servers required the full native Lean toolchain installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The release of the &lt;strong&gt;Ansatz Lean/JVM SDK (&lt;code&gt;org.replikativ/ansatz-lean-jvm:0.2.615&lt;/code&gt;)&lt;/strong&gt; changes this equation. It provides a pure JVM intermediate-representation (IR) interpreter that runs proved Lean functions directly on stock OpenJDK 17+.&lt;/p&gt;

&lt;p&gt;This unlocks an autonomous ground-truth loop: &lt;strong&gt;agents synthesize formally verified invariants in Lean, prove them against the Lean compiler, and deploy them directly into production Clojure and Java microservices.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Architecture: Build-Time Proofs, Run-Time JVM
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────────────────────────────────────────────────┐
│                   BUILD &amp;amp; PROOF STAGE                  │
│               (Linux x86-64 / CI / Docker)             │
│                                                        │
│  AI Agent writes:                                      │
│  • Settlement logic                                    │
│  • Invariant theorems (Conservation &amp;amp; Solvency)        │
│                                                        │
│                     ▼                                  │
│         Lean 4.33.1 Toolchain Check                    │
│    [ Fails: Agent self-corrects proof ]                │
│    [ Passes: Proof erased, IR compiled ]               │
│                     ▼                                  │
│            ledger.leanjvm Artifact                     │
│          + SHA-256 Manifest Fingerprint                │
└────────────────────────┬───────────────────────────────┘
                         │
                         ▼
┌────────────────────────────────────────────────────────┐
│                   PRODUCTION STAGE                     │
│              (Any OpenJDK 17+ Environment)             │
│                                                        │
│  Clojure / JVM Microservice                            │
│  • Loads ledger.leanjvm into pure Java Interpreter     │
│  • Zero native C / JNI / platform dependencies         │
│  • Managed 100% by JVM Garbage Collector               │
│  • Enforces instruction budgets (default: 2M ops)      │
│  • Exposes bidirectional host callbacks (IO)           │
└────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The division of labor is clean:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;At build time&lt;/strong&gt;, native Lean compiles the source, checks the proofs, and strips them away. The compiler packages the intermediate code, types, and layouts into a portable &lt;code&gt;.leanjvm&lt;/code&gt; artifact.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;At run time&lt;/strong&gt;, standard Clojure services interpret the intermediate representation. The production container needs no Lean toolchain.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Domain: A Conservation-of-Value Financial Settlement
&lt;/h2&gt;

&lt;p&gt;Consider an account settlement function. The business requires two non-negotiable invariants:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Solvency:&lt;/strong&gt; No account may be debited below its configured floor (zero).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conservation of Value:&lt;/strong&gt; The total amount debited must equal the total amount credited. No money appears or vanishes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see how an autonomous agent interacts with this system.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Agent Self-Correction Loop
&lt;/h2&gt;

&lt;p&gt;When an AI agent is instructed to write settlement logic, it often generates subtle bugs. Here is what happens when Lean's type checker acts as the agent's supervisor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Round 1: The Agent Hallucinates an Edge Case
&lt;/h3&gt;

&lt;p&gt;The agent drafts an initial version in &lt;code&gt;Ledger.lean&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lean"&gt;&lt;code&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="nc"&gt;Ledger&lt;/span&gt;

&lt;span class="n"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;transfer&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Nat&lt;/span&gt; × &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
  &lt;span class="c1"&gt;-- Naive transfer: subtracts without checking if balance &amp;lt; amount&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;theorem&lt;/span&gt; &lt;span class="n"&gt;transfer_conserves_value&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;transfer&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;
  &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt;
  &lt;span class="n"&gt;unfold&lt;/span&gt; &lt;span class="n"&gt;transfer&lt;/span&gt;
  &lt;span class="c1"&gt;-- Proof attempt fails when amount &amp;gt; fromBal due to Nat underflow truncation!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Lean, natural numbers (&lt;code&gt;Nat&lt;/code&gt;) truncate subtraction at zero (&lt;code&gt;3 - 5 = 0&lt;/code&gt;). Because of this, &lt;code&gt;fromBal - amount&lt;/code&gt; breaks conservation of value whenever &lt;code&gt;amount &amp;gt; fromBal&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;The Lean compiler rejects the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lean"&gt;&lt;code&gt;&lt;span class="nb"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unsolved&lt;/span&gt; &lt;span class="n"&gt;goals&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;
&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;
⊢ &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent cannot hallucinate or hand-wave this failure away. The build stops cold.&lt;/p&gt;

&lt;h3&gt;
  
  
  Round 2: Self-Correction with Machine-Checked Solvency
&lt;/h3&gt;

&lt;p&gt;The agent reads the compiler error, realizes &lt;code&gt;Nat&lt;/code&gt; subtraction truncates at zero, and refines the logic to guard the transfer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lean"&gt;&lt;code&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="nc"&gt;Ledger&lt;/span&gt;

&lt;span class="n"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;settleTransfer&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Nat&lt;/span&gt; × &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; ≤ &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;-- Rejected transfer preserves balances unchanged&lt;/span&gt;

&lt;span class="o"&gt;/--&lt;/span&gt; &lt;span class="nc"&gt;Theorem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Transfers&lt;/span&gt; &lt;span class="n"&gt;strictly&lt;/span&gt; &lt;span class="n"&gt;conserve&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="n"&gt;capital&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;-/&lt;/span&gt;
&lt;span class="n"&gt;theorem&lt;/span&gt; &lt;span class="n"&gt;settle_conserves_value&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;settleTransfer&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;
  &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt;
  &lt;span class="n"&gt;unfold&lt;/span&gt; &lt;span class="n"&gt;settleTransfer&lt;/span&gt;
  &lt;span class="n"&gt;split&lt;/span&gt;
  · &lt;span class="n"&gt;rename_i&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;
    &lt;span class="n"&gt;omega&lt;/span&gt;
  · &lt;span class="n"&gt;rfl&lt;/span&gt;

&lt;span class="o"&gt;/--&lt;/span&gt; &lt;span class="nc"&gt;Theorem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;The&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="n"&gt;never&lt;/span&gt; &lt;span class="n"&gt;drops&lt;/span&gt; &lt;span class="n"&gt;below&lt;/span&gt; &lt;span class="n"&gt;zero&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;solvency&lt;/span&gt; &lt;span class="n"&gt;guarantee&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;-/&lt;/span&gt;
&lt;span class="n"&gt;theorem&lt;/span&gt; &lt;span class="n"&gt;settle_preserves_solvency&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;settleTransfer&lt;/span&gt; &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;
  &lt;span class="n"&gt;f&lt;/span&gt; ≤ &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt;
  &lt;span class="n"&gt;unfold&lt;/span&gt; &lt;span class="n"&gt;settleTransfer&lt;/span&gt;
  &lt;span class="n"&gt;split&lt;/span&gt;
  · &lt;span class="n"&gt;rename_i&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;
    &lt;span class="n"&gt;omega&lt;/span&gt;
  · &lt;span class="n"&gt;rfl&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="nc"&gt;Ledger&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both proofs pass. Lean guarantees that no transaction can ever violate solvency or fabricate currency, across &lt;strong&gt;all infinite combinations&lt;/strong&gt; of &lt;code&gt;Nat&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Compiling the Verified Artifact
&lt;/h2&gt;

&lt;p&gt;During the CI build (currently supported on Linux x86-64 with &lt;code&gt;prlimit&lt;/code&gt;, or via Docker), the agent triggers artifact preparation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java -cp &lt;span class="s2"&gt;"$SDK_CLASSPATH"&lt;/span&gt; ansatz.lean.jvm.LeanPreparation \
  --source ./ledger \
  --sysroot &lt;span class="s2"&gt;"$LEAN_SYSROOT"&lt;/span&gt; \
  --producer-bundle &lt;span class="s2"&gt;"$PRODUCER_BUNDLE"&lt;/span&gt; \
  --cache &lt;span class="s2"&gt;"$COMPILER_CACHE"&lt;/span&gt; \
  --root-module Ledger \
  --entry Ledger.settleTransfer \
  --output ./ledger.leanjvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates &lt;code&gt;ledger.leanjvm&lt;/code&gt; and prints its SHA-256 fingerprint:&lt;br&gt;
&lt;code&gt;sha256:d8a2...3f10&lt;/code&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  3. Running Inside Clojure at the REPL
&lt;/h2&gt;

&lt;p&gt;In the production service, add the SDK dependency to &lt;code&gt;deps.edn&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:deps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;org.replikativ/ansatz-lean-jvm&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:mvn/version&lt;/span&gt; &lt;span class="s2"&gt;"0.2.615"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Load the artifact and invoke the formally proved function directly from the Clojure REPL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;ledger.core&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ansatz.lean.jvm&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;lean&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;clojure.java.io&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;io&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt; &lt;span class="nv"&gt;run-settlement&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;with-open&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;runtime&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/open&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
              &lt;span class="nv"&gt;input&lt;/span&gt;   &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;io/input-stream&lt;/span&gt; &lt;span class="s2"&gt;"ledger.leanjvm"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
              &lt;span class="nv"&gt;project&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/load-artifact&lt;/span&gt; &lt;span class="nv"&gt;runtime&lt;/span&gt; &lt;span class="nv"&gt;input&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;System/getenv&lt;/span&gt; &lt;span class="s2"&gt;"EXPECTED_MANIFEST_SHA256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;settle&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/function&lt;/span&gt; &lt;span class="nv"&gt;project&lt;/span&gt; &lt;span class="s2"&gt;"Ledger.settleTransfer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="c1"&gt;;; 1. Valid transfer: $500 from Acc1 ($10,000) to Acc2 ($1,000)&lt;/span&gt;
      &lt;span class="c1"&gt;;; 2. Overdraft attempt: $15,000 from Acc1 ($10,000) to Acc2 ($1,000)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:valid-transfer&lt;/span&gt;     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;settle&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="ss"&gt;:overdraft-rejected&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;settle&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="mi"&gt;15000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; (run-settlement)&lt;/span&gt;
&lt;span class="c1"&gt;;; =&amp;gt; {:valid-transfer     [9500N 1500N]&lt;/span&gt;
&lt;span class="c1"&gt;;;     :overdraft-rejected [10000N 1000N]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key runtime observations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clojure passes standard numbers and receives back persistent vectors containing &lt;code&gt;java.math.BigInteger&lt;/code&gt; instances.&lt;/li&gt;
&lt;li&gt;Zero JNI code or platform native bridges.&lt;/li&gt;
&lt;li&gt;Memory management is 100% handled by the JVM garbage collector.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Inversion of Control: Lean Calling Clojure
&lt;/h2&gt;

&lt;p&gt;Real business operations require dynamic runtime data—like querying fee tiers from a database or configuration file.&lt;/p&gt;

&lt;p&gt;Lean declares the external callback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lean"&gt;&lt;code&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="nc"&gt;Ledger&lt;/span&gt;

@&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;extern&lt;/span&gt; &lt;span class="s2"&gt;"ansatz_jvm_account_fee"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;opaque&lt;/span&gt; &lt;span class="n"&gt;getAccountFee&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; → &lt;span class="kt"&gt;IO&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;

&lt;span class="n"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;settleWithFee&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;IO&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Nat&lt;/span&gt; × &lt;span class="nc"&gt;Nat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;feeRate&lt;/span&gt; ← &lt;span class="n"&gt;getAccountFee&lt;/span&gt; &lt;span class="n"&gt;tier&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;feeRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;totalDebit&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;fee&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;totalDebit&lt;/span&gt; ≤ &lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="n"&gt;pure&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;totalDebit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;pure&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromBal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toBal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="nc"&gt;Ledger&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Clojure, supply the implementation under the declaration's name when loading the artifact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;host-bindings&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Ledger.getAccountFee"&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:implementation-id&lt;/span&gt; &lt;span class="s2"&gt;"fees/v1"&lt;/span&gt;
    &lt;span class="ss"&gt;:effect&lt;/span&gt; &lt;span class="ss"&gt;:io&lt;/span&gt;
    &lt;span class="ss"&gt;:fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nv"&gt;tier&lt;/span&gt;
            &lt;span class="s2"&gt;"vip"&lt;/span&gt;      &lt;span class="mi"&gt;0N&lt;/span&gt;     &lt;span class="c1"&gt;;; Zero fee&lt;/span&gt;
            &lt;span class="s2"&gt;"standard"&lt;/span&gt; &lt;span class="mi"&gt;15N&lt;/span&gt;    &lt;span class="c1"&gt;;; 1.5% fee&lt;/span&gt;
            &lt;span class="mi"&gt;50N&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;;; Default 5.0%&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;with-open&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;runtime&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/open&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
              &lt;span class="nv"&gt;input&lt;/span&gt;   &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;io/input-stream&lt;/span&gt; &lt;span class="s2"&gt;"ledger.leanjvm"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
              &lt;span class="nv"&gt;project&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/load-artifact&lt;/span&gt; &lt;span class="nv"&gt;runtime&lt;/span&gt; &lt;span class="nv"&gt;input&lt;/span&gt; 
                                          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;System/getenv&lt;/span&gt; &lt;span class="s2"&gt;"EXPECTED_MANIFEST_SHA256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                          &lt;span class="nv"&gt;host-bindings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;;; IO functions return an IOResult object carrying values or errors&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;lean/call&lt;/span&gt; &lt;span class="nv"&gt;project&lt;/span&gt; &lt;span class="s2"&gt;"Ledger.settleWithFee"&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt; &lt;span class="s2"&gt;"standard"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.isOk&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.getValue&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ex-info&lt;/span&gt; &lt;span class="s2"&gt;"Lean IO Error"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:cause&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.getError&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;;; =&amp;gt; [7970N 3000N]  ; Total debit: 2000 + 30 fee = 2030&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mathematical proofs that parameterize over host inputs remain sound, even when values are resolved dynamically by host Clojure code.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Architectural Differentiator: Forkable Execution State
&lt;/h2&gt;

&lt;p&gt;Why run Lean through a pure JVM interpreter instead of compiling hot machine code? &lt;/p&gt;

&lt;p&gt;The Simmis team highlighted an architectural breakthrough: &lt;strong&gt;execution state forkability&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Because Lean's entire execution state (call frames, heap objects, and registers) is stored as standard JVM heap objects, the engine can &lt;strong&gt;clone that state mid-computation&lt;/strong&gt;. Pausing an engine allows branching it into two independent engines that proceed down separate computational paths.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: While the core Ansatz engine implements state forking internally today, the public SDK does not expose fork handles yet. It represents groundwork for upcoming releases.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For future AI reasoning pipelines, this capability enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Counterfactual Branching:&lt;/strong&gt; An agent pauses a complex financial settlement, branches the execution into two what-if paths (e.g., assessing different liquidity routing strategies), and compares the outcomes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rollback without Transaction Resets:&lt;/strong&gt; Discarding a failed branch requires only dropping the cloned JVM object, with zero external database rollback needed.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. Safety &amp;amp; Operational Guardrails
&lt;/h2&gt;

&lt;p&gt;When executing autonomous agent code in production, defensive constraints are mandatory:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guardrail&lt;/th&gt;
&lt;th&gt;Enforcement Mechanism&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Infinite Recursion / DOS&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Invocations run under strict instruction budgets (default: 2,000,000 steps) and wall-clock timeouts (default: 5.0s).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Tampered / Stale Artifacts&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Artifact loading strictly validates the build-time SHA-256 manifest hash before execution.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Error Isolation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Out-of-budget calls fail cleanly with &lt;code&gt;ProjectFailed&lt;/code&gt;. The service restarts the engine via &lt;code&gt;project.restart()&lt;/code&gt;, discarding corrupted state while preserving verified code handles.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Language Constraints&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The current release enforces closed, first-order signatures across host boundaries and caps project modules at 128 (beyond Lean's &lt;code&gt;Init&lt;/code&gt;).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The conversation around AI coding agents has focused primarily on generating code and generating unit tests. But in high-consequence domains like finance, tests cannot establish absolute correctness.&lt;/p&gt;

&lt;p&gt;By uniting &lt;strong&gt;Lean 4's proof assistant&lt;/strong&gt; with the &lt;strong&gt;JVM's operational maturity&lt;/strong&gt;, tools like Ansatz establish a practical verification bridge:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Agents specify and prove&lt;/strong&gt; invariants rather than guessing implementations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The compiler enforces ground truth&lt;/strong&gt;, rejecting flawed edge cases with actionable counter-examples.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The runtime executes natively on standard JVMs&lt;/strong&gt;, eliminating native operational overhead.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The future of autonomous systems isn't just agents that code faster—it's agents that prove their work before hitting production.&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primary Source:&lt;/strong&gt; &lt;a href="https://simm.is/blog/lean-on-the-jvm/" rel="noopener noreferrer"&gt;Simmis: Lean on the JVM: proved functions for Java and Clojure&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SDK Artifact:&lt;/strong&gt; &lt;a href="https://clojars.org/org.replikativ/ansatz-lean-jvm" rel="noopener noreferrer"&gt;&lt;code&gt;org.replikativ/ansatz-lean-jvm&lt;/code&gt; on Clojars&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lean 4 Guide:&lt;/strong&gt; &lt;a href="https://lean-lang.org/functional_programming_in_lean/" rel="noopener noreferrer"&gt;Functional Programming in Lean&lt;/a&gt; by David Thrane Christiansen&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Crafted with AI: Research, drafting, review, and refinement assisted by frontier AI models.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>java</category>
      <category>ai</category>
      <category>lean4</category>
    </item>
    <item>
      <title>Build a temperature converter web page in Clojure (no experience needed)</title>
      <dc:creator>Thiago Carvalho</dc:creator>
      <pubDate>Tue, 03 Nov 2026 14:03:00 +0000</pubDate>
      <link>https://dev.to/thiagooak/build-a-temperature-converter-web-page-in-clojure-no-experience-needed-22mh</link>
      <guid>https://dev.to/thiagooak/build-a-temperature-converter-web-page-in-clojure-no-experience-needed-22mh</guid>
      <description>&lt;p&gt;This is part four of a series teaching Clojure to people with little or no programming experience.&lt;/p&gt;

&lt;p&gt;In Part 3, you built a few static pages that look the same for every visitor.&lt;/p&gt;

&lt;p&gt;Now we'll build a small dynamic page, one that changes depending on what the visitor asks for. It converts temperatures in Celsius to Fahrenheit. You'll also meet the REPL, the "smarter way of working" mentioned in Part 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Pull values out of the URL
&lt;/h2&gt;

&lt;p&gt;First, bring in Clojure's string functions. Update the &lt;code&gt;ns&lt;/code&gt; at the top of &lt;code&gt;src/app/core.clj&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;clojure.string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:gen-class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can use &lt;code&gt;str/split&lt;/code&gt;, &lt;code&gt;str/blank?&lt;/code&gt;, and friends.&lt;/p&gt;

&lt;p&gt;Then add these two functions above &lt;code&gt;handler&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;java.net.URLDecoder/decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/blank?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;into&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/split&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="no"&gt;:let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/split&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)]]&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="nf"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))]))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file. Let's take it apart:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URLs can't contain spaces or most symbols, so browsers &lt;em&gt;encode&lt;/em&gt; them. A space becomes &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; becomes &lt;code&gt;%3C&lt;/code&gt;. &lt;code&gt;url-decode&lt;/code&gt; puts them back to their original form.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parse-query&lt;/code&gt; splits the text on &lt;code&gt;&amp;amp;&lt;/code&gt; to get one chunk per parameter (&lt;code&gt;a=1&amp;amp;b=2&lt;/code&gt; becomes &lt;code&gt;a=1&lt;/code&gt; and &lt;code&gt;b=2&lt;/code&gt;). &lt;code&gt;#"&amp;amp;"&lt;/code&gt; is a &lt;em&gt;pattern&lt;/em&gt;: it means "wherever you find an &lt;code&gt;&amp;amp;&lt;/code&gt;".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for&lt;/code&gt; goes through the chunks one at a time and builds a new collection from them. Think of it as "for each chunk, do this".&lt;/li&gt;
&lt;li&gt;For each chunk it splits on the first &lt;code&gt;=&lt;/code&gt; to get a key and a value. &lt;code&gt;[k v]&lt;/code&gt; is a shortcut that takes the two pieces apart and names them &lt;code&gt;k&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt;. If the chunk has no &lt;code&gt;=&lt;/code&gt; at all (as in &lt;code&gt;?celsius&lt;/code&gt;), there is no &lt;code&gt;v&lt;/code&gt;, so &lt;code&gt;(or v "")&lt;/code&gt; uses empty text instead.&lt;/li&gt;
&lt;li&gt;It decodes both, and &lt;code&gt;into {}&lt;/code&gt; collects the key/value pairs into a map.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;when-not&lt;/code&gt; runs its body only if the condition is false. If the query string is blank, there is nothing to parse, so &lt;code&gt;parse-query&lt;/code&gt; returns &lt;code&gt;nil&lt;/code&gt;, which means "nothing here". That's fine: looking something up in &lt;code&gt;nil&lt;/code&gt; just gives you &lt;code&gt;nil&lt;/code&gt; back.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Try it in the REPL
&lt;/h3&gt;

&lt;p&gt;How do you know &lt;code&gt;parse-query&lt;/code&gt; works? You could wire it into &lt;code&gt;handler&lt;/code&gt;, restart the server and visit a URL. Or you can just &lt;em&gt;call it&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Open a new terminal (&lt;strong&gt;Terminal&lt;/strong&gt; &amp;gt; &lt;strong&gt;New Terminal&lt;/strong&gt;) and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll get a prompt that looks like &lt;code&gt;user=&amp;gt;&lt;/code&gt;.&lt;br&gt;
This is a REPL (Read, Evaluate, Print, Loop): you type a Clojure expression, it runs it and shows you the result.&lt;br&gt;
Type or paste each expression below into the REPL and press Enter. The &lt;code&gt;;;&lt;/code&gt; lines show what you should see back, so you don't need to type them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; nil&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius=20&amp;amp;unit=c"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; {"celsius" "20", "unit" "c"}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; nil&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;require&lt;/code&gt; loads your file. The &lt;code&gt;'&lt;/code&gt; in front of &lt;code&gt;app.core&lt;/code&gt; tells Clojure "don't try to look it up right now". To call one of your functions, put its namespace in front: &lt;code&gt;app.core/parse-query&lt;/code&gt; is the &lt;code&gt;parse-query&lt;/code&gt; from &lt;code&gt;src/app/core.clj&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No server, no browser and no restart. REPL-driven development lets you iterate and explore your code with instant feedback. In this series we'll use the REPL directly by typing text in a terminal window, but if you installed &lt;a href="https://calva.io" rel="noopener noreferrer"&gt;Calva&lt;/a&gt; in Part 1, it can also run code straight from your editor.&lt;/p&gt;

&lt;p&gt;Leave the REPL open: we'll come back to it in the next step. Later, when you're done with it, close it by pressing &lt;code&gt;Ctrl+D&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Convert Celsius to Fahrenheit
&lt;/h2&gt;

&lt;p&gt;The formula to convert from Celsius to Fahrenheit is &lt;code&gt;F = C × 9/5 + 32&lt;/code&gt;.&lt;br&gt;
Add it above &lt;code&gt;handler&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="n"&gt;/5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;(* c 9/5)&lt;/code&gt; means "&lt;code&gt;c&lt;/code&gt; times 9/5", and &lt;code&gt;(+ ... 32)&lt;/code&gt; adds 32 to that. In Clojure the operation comes first, just like any other function: &lt;code&gt;(+ 1 2)&lt;/code&gt; is 1 plus 2.&lt;/p&gt;

&lt;p&gt;Save the file and go back to the REPL. It doesn't notice that the file changed, so ask it to load the file again (note the &lt;code&gt;:reload&lt;/code&gt;), then try a few temperatures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:reload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; nil&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;20.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; 68.0&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;100.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; 212.0&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;-40.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; -40.0&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works! -40 is the point where the temperature is the same in both scales.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wire it to the URL
&lt;/h3&gt;

&lt;p&gt;On the website, the number won't come from you typing &lt;code&gt;20.0&lt;/code&gt;. It will come from the URL, through &lt;code&gt;parse-query&lt;/code&gt;.&lt;br&gt;
Let's try that. &lt;code&gt;get&lt;/code&gt; looks up a key in a map, so this pulls the value of &lt;code&gt;"celsius"&lt;/code&gt; out of what &lt;code&gt;parse-query&lt;/code&gt; returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius=20"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; "20"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now give that value to &lt;code&gt;celsius-&amp;gt;fahrenheit&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius=20"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; Execution error (ClassCastException) at app.core/celsius-&amp;gt;fahrenheit (core.clj:...).&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; class java.lang.String cannot be cast to class java.lang.Number ...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error tells you what happened (&lt;code&gt;String cannot be cast to Number&lt;/code&gt;) and where (&lt;code&gt;celsius-&amp;gt;fahrenheit&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Look closely at the result of the &lt;code&gt;get&lt;/code&gt; above: it's &lt;code&gt;"20"&lt;/code&gt;, with quotes. That's text, not the number &lt;code&gt;20&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;celsius-&amp;gt;fahrenheit&lt;/code&gt; expects a number, and &lt;code&gt;parse-query&lt;/code&gt; returns text even when it looks like a number. We need to convert it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;parse-double&lt;/code&gt; converts text to a number. It comes with Clojure, so it doesn't need the &lt;code&gt;app.core/&lt;/code&gt; prefix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; 20.0&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it should work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; 68.0&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Run the server from the REPL
&lt;/h2&gt;

&lt;p&gt;So far you've run the server in its own terminal with &lt;code&gt;clojure -M:run&lt;/code&gt;, and restarting it meant &lt;code&gt;Ctrl+C&lt;/code&gt; and typing the command again.&lt;br&gt;
You already have a REPL open, so let's run the server from there instead and do everything in one place.&lt;/p&gt;

&lt;p&gt;If the server from Part 3 is still running in another terminal, stop it with &lt;code&gt;Ctrl+C&lt;/code&gt;. Two programs can't both use port 8080 at the same time.&lt;/p&gt;

&lt;p&gt;At the bottom of &lt;code&gt;src/app/core.clj&lt;/code&gt;, replace &lt;code&gt;-main&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;defonce&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stop-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;reset!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;start-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;stop-server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Integer/parseInt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;System/getenv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"8080"&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;reset!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;start-server&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a lot of code here, so let's go slowly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;atom&lt;/code&gt; is a box that holds a value that can change. Ours starts out holding &lt;code&gt;nil&lt;/code&gt; (nothing), and it will hold the running server.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;defonce&lt;/code&gt; is like &lt;code&gt;def&lt;/code&gt;, but it only happens once. A &lt;code&gt;:reload&lt;/code&gt; runs every line of the file again, and without &lt;code&gt;defonce&lt;/code&gt; the box would be replaced by an empty one, and we'd lose track of a server that is still running.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@server&lt;/code&gt; looks inside the box, and &lt;code&gt;reset!&lt;/code&gt; puts a new value in it. The &lt;code&gt;!&lt;/code&gt; at the end of a name is a convention that warns "this may change something".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http/run-server&lt;/code&gt; starts the server and gives back a &lt;em&gt;function that stops it&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stop-server&lt;/code&gt; uses &lt;code&gt;when-let&lt;/code&gt;: if the box holds something, name it &lt;code&gt;stop&lt;/code&gt;, call it, and empty the box. If the box is empty, there's nothing to stop, so it does nothing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;start-server&lt;/code&gt; always calls &lt;code&gt;stop-server&lt;/code&gt; first. That's what makes it safe to run as many times as you like: every call is a restart.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;let&lt;/code&gt; with &lt;code&gt;port&lt;/code&gt; is the same code that used to be in &lt;code&gt;-main&lt;/code&gt;, moved into &lt;code&gt;start-server&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-main&lt;/code&gt; now just calls &lt;code&gt;start-server&lt;/code&gt;, so &lt;code&gt;clojure -M:run&lt;/code&gt; and Vercel still work exactly as before.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Save the file. Then, in the REPL, load the new code and start the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:reload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; nil&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/start-server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; Server running on port 8080&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt;: it's your website, running from the REPL.&lt;/p&gt;

&lt;p&gt;From now on, this is the rhythm: &lt;strong&gt;edit, save, reload, restart&lt;/strong&gt;. Reloading is the &lt;code&gt;require&lt;/code&gt; with &lt;code&gt;:reload&lt;/code&gt;, and restarting is &lt;code&gt;(app.core/start-server)&lt;/code&gt;. You can run both in one go by pasting them on the same line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:reload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/start-server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop the server, run &lt;code&gt;(app.core/stop-server)&lt;/code&gt;. Closing the REPL with &lt;code&gt;Ctrl+D&lt;/code&gt; stops it too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Build the page
&lt;/h2&gt;

&lt;p&gt;Let's put this conversion to work in a page. Add this function above &lt;code&gt;handler&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Celsius to Fahrenheit"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Celsius to Fahrenheit&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;C is "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;F&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; gives a name to a value: &lt;code&gt;c&lt;/code&gt; is the number &lt;code&gt;parse-double&lt;/code&gt; got from the text.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(get params "celsius")&lt;/code&gt; is the same lookup you just tried in the REPL. In Part 3, &lt;code&gt;(:uri req)&lt;/code&gt; worked because &lt;code&gt;:uri&lt;/code&gt; is a keyword. The keys in &lt;code&gt;params&lt;/code&gt; are &lt;em&gt;text&lt;/em&gt; (&lt;code&gt;"celsius"&lt;/code&gt;), and text can't look itself up, so we use &lt;code&gt;get&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;deg;&lt;/code&gt; is HTML's way of writing the degree sign.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And add a route to &lt;code&gt;handler&lt;/code&gt;, before the 404 at the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/convert"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:query-string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;not-found-page&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file, then reload and restart in the REPL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:reload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app.core/start-server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then visit &lt;a href="http://localhost:8080/convert?celsius=20" rel="noopener noreferrer"&gt;http://localhost:8080/convert?celsius=20&lt;/a&gt;.&lt;br&gt;
You should see &lt;code&gt;20.0°C is 68.0°F&lt;/code&gt;. Try &lt;code&gt;celsius=100&lt;/code&gt; and &lt;code&gt;celsius=-40&lt;/code&gt; too.&lt;/p&gt;

&lt;p&gt;Now try two addresses a visitor could easily go to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visit &lt;code&gt;/convert&lt;/code&gt; with nothing after it.&lt;/li&gt;
&lt;li&gt;Visit &lt;code&gt;/convert?celsius=banana&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of these produce an error page, with messages like &lt;code&gt;Expected string, got nil&lt;/code&gt; and &lt;code&gt;Cannot invoke "Object.getClass()" because "x" is null&lt;/code&gt;. The REPL will show you the full error message.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Fail gracefully
&lt;/h2&gt;

&lt;p&gt;There are two different problems here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No value at all.&lt;/strong&gt; &lt;code&gt;/convert&lt;/code&gt; has no &lt;code&gt;celsius&lt;/code&gt;, so &lt;code&gt;get&lt;/code&gt; returns &lt;code&gt;nil&lt;/code&gt;, and &lt;code&gt;parse-double&lt;/code&gt; refuses it: that's the &lt;code&gt;Expected string, got nil&lt;/code&gt; error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A value that isn't a number.&lt;/strong&gt; &lt;code&gt;parse-double&lt;/code&gt; doesn't crash on &lt;code&gt;"banana"&lt;/code&gt;. It returns &lt;code&gt;nil&lt;/code&gt;, its way of saying "this isn't a number". The crash comes one step later, when &lt;code&gt;celsius-&amp;gt;fahrenheit&lt;/code&gt; tries to do math with &lt;code&gt;nil&lt;/code&gt;: that's the &lt;code&gt;Object.getClass()&lt;/code&gt; error.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In both cases there's nothing to convert, so the page should simply show no result. Replace &lt;code&gt;convert-page&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Celsius to Fahrenheit"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Celsius to Fahrenheit&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
                 &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;C is "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;F&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(get params "celsius" "")&lt;/code&gt; has a third part: a default. If there's no &lt;code&gt;"celsius"&lt;/code&gt; in the map, &lt;code&gt;get&lt;/code&gt; returns &lt;code&gt;""&lt;/code&gt; (empty text) instead of &lt;code&gt;nil&lt;/code&gt;. &lt;code&gt;parse-double&lt;/code&gt; is happy with empty text: it isn't a number, so it returns &lt;code&gt;nil&lt;/code&gt;. That turns the first problem into the second one.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;when-let&lt;/code&gt;, which you saw in &lt;code&gt;stop-server&lt;/code&gt;, handles the second problem. It runs &lt;code&gt;(parse-double celsius-str)&lt;/code&gt;, and if the result is a number, it names it &lt;code&gt;c&lt;/code&gt; and builds the result paragraph. If the result is &lt;code&gt;nil&lt;/code&gt;, it skips its body and returns &lt;code&gt;nil&lt;/code&gt;, and &lt;code&gt;str&lt;/code&gt; treats &lt;code&gt;nil&lt;/code&gt; as empty text, so the page shows no result at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice how &lt;code&gt;nil&lt;/code&gt; did the work here. We didn't stop it from showing up, we only did the math when there was something.&lt;/p&gt;

&lt;p&gt;Save the file, then reload and restart in the REPL (&lt;code&gt;(require 'app.core :reload) (app.core/start-server)&lt;/code&gt;) and try the two broken URLs again. Now both give you the page, without a result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Add a form
&lt;/h2&gt;

&lt;p&gt;Nobody wants to edit URLs by hand. Let's add a form so visitors can type a value and press a button.&lt;br&gt;
Replace &lt;code&gt;convert-page&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Celsius to Fahrenheit"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Celsius to Fahrenheit&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;form method=\"get\" action=\"/convert\"&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;input type=\"text\" name=\"celsius\" placeholder=\"Enter Celsius\"&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;button type=\"submit\"&amp;gt;Convert&amp;lt;/button&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/form&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
                 &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;C is "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;F&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; sends the visitor to &lt;code&gt;/convert?celsius=whatever-they-typed&lt;/code&gt;, which is the same address you've been typing by hand.&lt;br&gt;
The box comes back empty after they press the button, but the result line shows the number they converted.&lt;/p&gt;

&lt;p&gt;Save the file, then reload and restart in the REPL (&lt;code&gt;(require 'app.core :reload) (app.core/start-server)&lt;/code&gt;) and use the form.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; you've now got an interactive page, one that responds differently depending on what a visitor types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  The whole file
&lt;/h2&gt;

&lt;p&gt;Here is the full &lt;code&gt;src/app/core.clj&lt;/code&gt; at this point. If something isn't working, compare yours to this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;clojure.string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:gen-class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;style&amp;gt;body{font-family:sans-serif;max-width:600px;margin:40px auto;padding:0 20px}"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"nav a{margin-right:12px}&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;nav&amp;gt;&amp;lt;a href=\"/\"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;a href=\"/about\"&amp;gt;About&amp;lt;/a&amp;gt;&amp;lt;/nav&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;home-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Home"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Hi, I'm Carvalho&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;Welcome to my corner of the internet.&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;ul&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;li&amp;gt;&amp;lt;a href=\"https://github.com\"&amp;gt;GitHub&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/ul&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;about-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"About"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;About Me&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;I'm learning Clojure and building my first website!&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;not-found-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Not Found"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;404 - Page Not Found&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;java.net.URLDecoder/decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/blank?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;into&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/split&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;query-string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="no"&gt;:let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str/split&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)]]&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="nf"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;url-decode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))]))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="n"&gt;/5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"celsius"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Celsius to Fahrenheit"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Celsius to Fahrenheit&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;form method=\"get\" action=\"/convert\"&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;input type=\"text\" name=\"celsius\" placeholder=\"Enter Celsius\"&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;button type=\"submit\"&amp;gt;Convert&amp;lt;/button&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/form&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;celsius-str&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="w"&gt;
                 &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;C is "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;celsius-&amp;gt;fahrenheit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;amp;deg;F&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/convert"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;convert-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parse-query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:query-string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;not-found-page&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;defonce&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stop-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;when-let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;reset!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;start-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;stop-server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Integer/parseInt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;System/getenv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"8080"&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;reset!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;start-server&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy it
&lt;/h2&gt;

&lt;p&gt;Same command as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vercel deploy &lt;span class="nt"&gt;--prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;/convert&lt;/code&gt; on your live link and try the form. Then throw some bad input at it: no value at all, and &lt;code&gt;banana&lt;/code&gt;.&lt;br&gt;
Both should give you a normal page.&lt;/p&gt;

&lt;h2&gt;
  
  
  If something went wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Could not locate app/core&lt;/code&gt;&lt;/strong&gt; in the REPL: you started &lt;code&gt;clojure&lt;/code&gt; outside your &lt;code&gt;my-site&lt;/code&gt; folder. Press &lt;code&gt;Ctrl+D&lt;/code&gt;, close that terminal, and open a new one with &lt;strong&gt;Terminal&lt;/strong&gt; &amp;gt; &lt;strong&gt;New Terminal&lt;/strong&gt;. VS Code starts it inside &lt;code&gt;my-site&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The browser shows old content&lt;/strong&gt;: the REPL keeps its own copy of the code. Save the file, then reload and restart (&lt;code&gt;(require 'app.core :reload) (app.core/start-server)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Address already in use&lt;/code&gt;&lt;/strong&gt; when you run &lt;code&gt;(app.core/start-server)&lt;/code&gt;: another program is using port 8080, most likely a &lt;code&gt;clojure -M:run&lt;/code&gt; still running in another terminal. Stop it with &lt;code&gt;Ctrl+C&lt;/code&gt; and try again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Syntax error (ClassNotFoundException)&lt;/code&gt; mentioning &lt;code&gt;app.core&lt;/code&gt;&lt;/strong&gt;: this REPL hasn't loaded your file yet. Run &lt;code&gt;(require 'app.core)&lt;/code&gt; first. A new REPL always needs it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;No such var: app.core/start-server&lt;/code&gt;&lt;/strong&gt;: the REPL hasn't loaded your latest code. Save the file and run the &lt;code&gt;require&lt;/code&gt; with &lt;code&gt;:reload&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Unable to resolve symbol: url-decode&lt;/code&gt;&lt;/strong&gt; (or &lt;code&gt;parse-query&lt;/code&gt;, &lt;code&gt;celsius-&amp;gt;fahrenheit&lt;/code&gt;...): the function is defined &lt;em&gt;below&lt;/em&gt; the code that uses it. Move it above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;No such namespace: str&lt;/code&gt;&lt;/strong&gt;: the &lt;code&gt;[clojure.string :as str]&lt;/code&gt; line is missing from the &lt;code&gt;ns&lt;/code&gt; at the top of the file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Expected string, got nil&lt;/code&gt; on the page&lt;/strong&gt;: &lt;code&gt;parse-double&lt;/code&gt; got &lt;code&gt;nil&lt;/code&gt;. Check that &lt;code&gt;convert-page&lt;/code&gt; uses &lt;code&gt;(get params "celsius" "")&lt;/code&gt;, with the &lt;code&gt;""&lt;/code&gt; default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Cannot invoke "Object.getClass()"&lt;/code&gt; on the page&lt;/strong&gt;: &lt;code&gt;convert-page&lt;/code&gt; is doing math on &lt;code&gt;nil&lt;/code&gt;. Check that the result paragraph is inside the &lt;code&gt;when-let&lt;/code&gt; from Step 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Everything that comes from a URL is text. &lt;code&gt;parse-query&lt;/code&gt; turns &lt;code&gt;celsius=20&lt;/code&gt; into a map, and &lt;code&gt;parse-double&lt;/code&gt; turns the text &lt;code&gt;"20"&lt;/code&gt; into a number.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;when-let&lt;/code&gt; runs some code only when a value is there.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;get&lt;/code&gt; can take a default, like &lt;code&gt;(get params "celsius" "")&lt;/code&gt;, for when the key isn't in the map.&lt;/li&gt;
&lt;li&gt;The REPL lets you test your functions without having to wire them to the rest of the app and restart the server.&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;atom&lt;/code&gt; holds a value that changes, like the running server. &lt;code&gt;start-server&lt;/code&gt; stops any old server before starting a new one, so restarting from the REPL is one line you can run again and again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;So far, every page is a function you wrote.&lt;br&gt;
In the next part we'll build pages out of &lt;em&gt;data&lt;/em&gt;: a blog that lists whatever files happen to be in a folder.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>clojure</category>
    </item>
    <item>
      <title>Clojure Explained: A Modern Lisp on the JVM</title>
      <dc:creator>The Practical Developer</dc:creator>
      <pubDate>Tue, 27 Oct 2026 17:49:32 +0000</pubDate>
      <link>https://dev.to/practicaldevblog/clojure-explained-a-modern-lisp-on-the-jvm-1o5d</link>
      <guid>https://dev.to/practicaldevblog/clojure-explained-a-modern-lisp-on-the-jvm-1o5d</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Lisp is the second-oldest programming language still in use, and most programmers have never written it, yet its ideas (code as data, functions as values, macros) shaped everything after it. Clojure, released in 2007, is Lisp rebuilt for the modern world: it runs on the JVM, uses every Java library, and replaces Lisp's mutable lists with immutable data structures. It is the language that convinced a generation of sceptics that parentheses are not a problem: they are the point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Immutable data, code as data, and the REPL
&lt;/h2&gt;

&lt;p&gt;Clojure's model rests on a few distinctive ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutable data by default&lt;/strong&gt;: maps, vectors, and sets never change in place; "updating" returns a new version, so concurrent code shares data safely and old versions stay available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code as data&lt;/strong&gt;: Clojure code is itself a data structure (lists), so programs can manipulate programs: macros, the feature other languages fake with code generation, are native.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The REPL&lt;/strong&gt;: develop interactively: evaluate expressions, inspect state, and reshape a running program without restarting it. The REPL is not a toy; it is the workflow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JVM hosted&lt;/strong&gt;: every Java library works, so Clojure programs deploy wherever Java does, with none of the ecosystem risk of a niche runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A tiny example shows the shape: a function, a map, and immutable transformation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; A user, and a function that "ages" them: returning a new map&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Ayesha"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:age&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;birthday&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:age&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;birthday&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; =&amp;gt; {:name "Ayesha" :age 26}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; user itself is unchanged: still 25&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No mutation, no classes, just data and functions, and the original value is still there, untouched, for any other code that needs it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest trade
&lt;/h2&gt;

&lt;p&gt;Clojure's trade is familiarity and hiring: parentheses and prefix notation take adjustment, startup time is JVM-slow, and the talent pool is small. Error messages, from the JVM stack, can be cryptic. Choose Clojure when immutable data and interactive development matter most, especially for data pipelines and backends, and choose a mainstream JVM language when team familiarity dominates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lisp, modernised
&lt;/h2&gt;

&lt;p&gt;Clojure is a modern Lisp on the JVM: immutable data, code as data, and REPL-driven development, with every Java library available. It trades familiarity for simplicity that scales, and for programmers who learn it, parentheses stop looking strange and start looking honest.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://practicaldevblog.blogspot.com/2026/10/clojure-explained-modern-lisp-on-jvm.html" rel="noopener noreferrer"&gt;https://practicaldevblog.blogspot.com/2026/10/clojure-explained-modern-lisp-on-jvm.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>programming</category>
      <category>beginners</category>
      <category>functional</category>
    </item>
    <item>
      <title>Build a multi-page website in Clojure: pages, links and a 404 page</title>
      <dc:creator>Thiago Carvalho</dc:creator>
      <pubDate>Mon, 26 Oct 2026 03:01:46 +0000</pubDate>
      <link>https://dev.to/thiagooak/learning-clojure-from-scratch-part-3-make-it-yours-2f28</link>
      <guid>https://dev.to/thiagooak/learning-clojure-from-scratch-part-3-make-it-yours-2f28</guid>
      <description>&lt;p&gt;This is part three of a series teaching Clojure to people with little or no programming experience.&lt;br&gt;
In Part 1 you ran a web server on your computer.&lt;br&gt;
In Part 2 you put it on the internet.&lt;/p&gt;

&lt;p&gt;In this part you'll go from a website that says &lt;code&gt;Hello, World!&lt;/code&gt; to a website with a home page, an about page, and a polite message for URLs that don't exist.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Look at what the server receives
&lt;/h2&gt;

&lt;p&gt;Before we start building the new pages, let's look at the information available to &lt;code&gt;handler&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Temporarily change &lt;code&gt;handler&lt;/code&gt; in &lt;code&gt;src/app/core.clj&lt;/code&gt; so it sends the request back to you as text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;pr-str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two changes: &lt;code&gt;_req&lt;/code&gt; is now &lt;code&gt;req&lt;/code&gt; because &lt;code&gt;handler&lt;/code&gt; is using it, and the body is now &lt;code&gt;(pr-str req)&lt;/code&gt;, which means "print this value as text".&lt;/p&gt;

&lt;p&gt;Remember the rhythm from Part 1: &lt;strong&gt;edit, stop, start, refresh&lt;/strong&gt;.&lt;br&gt;
Stop the server if it's still running (&lt;code&gt;Ctrl+C&lt;/code&gt;), start it again with &lt;code&gt;clojure -M:run&lt;/code&gt;, and open &lt;a href="http://localhost:8080/hello?name=carvalho" rel="noopener noreferrer"&gt;http://localhost:8080/hello?name=carvalho&lt;/a&gt;.&lt;br&gt;
You'll see something like this (shortened here):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:remote-addr&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"0:0:0:0:0:0:0:1"&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"accept"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html,..."&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"host"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"localhost:8080"&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"user-agent"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Mozilla/5.0 ..."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:server-port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:query-string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"name=carvalho"&lt;/span&gt;&lt;span class="n"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:request-method&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:get,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="n"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the request. It's a map, just like the response.&lt;br&gt;
Two of its keys matter for this series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:uri&lt;/code&gt; is the part of the address after the host name: &lt;code&gt;/hello&lt;/code&gt;. We'll use it in this part to choose which page to show.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:query-string&lt;/code&gt; is whatever comes after the &lt;code&gt;?&lt;/code&gt;: &lt;code&gt;name=carvalho&lt;/code&gt;. We'll use it in the next part.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Change the address to &lt;code&gt;/about&lt;/code&gt; or &lt;code&gt;/anything-you-like&lt;/code&gt; and watch &lt;code&gt;:uri&lt;/code&gt; change.&lt;br&gt;
Now that you know what a request contains, let's build the new pages.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Send back HTML instead of plain text
&lt;/h2&gt;

&lt;p&gt;Put &lt;code&gt;handler&lt;/code&gt; back to saying hello (and &lt;code&gt;req&lt;/code&gt; back to &lt;code&gt;_req&lt;/code&gt;, since we're not looking at the request for now), but make it send HTML text.&lt;br&gt;
Change &lt;code&gt;Content-Type&lt;/code&gt; from &lt;code&gt;text/plain&lt;/code&gt; to &lt;code&gt;text/html&lt;/code&gt; and write HTML in the body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Content-Type&lt;/code&gt; tells the browser how to read what it receives.&lt;br&gt;
&lt;code&gt;text/plain&lt;/code&gt; means "show it as text", &lt;code&gt;text/html&lt;/code&gt; means "this is an HTML page, interpret the tags".&lt;br&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;...&amp;lt;/h1&amp;gt;&lt;/code&gt; is the HTML tag for a big heading.&lt;/p&gt;

&lt;p&gt;Restart, refresh, and the greeting becomes a heading.&lt;/p&gt;

&lt;p&gt;If you're new to HTML, a few tags will get you far:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;Title&amp;lt;/h1&amp;gt;&lt;/code&gt; for a heading.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;p&amp;gt;Some text&amp;lt;/p&amp;gt;&lt;/code&gt; for a paragraph.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;a href="https://example.com"&amp;gt;a link&amp;lt;/a&amp;gt;&lt;/code&gt; for a link.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; for a bulleted list: the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; is the list, and each &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; is one item in it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; for a group of navigation links. You'll see it in the next step.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 3: Create a reusable page template
&lt;/h2&gt;

&lt;p&gt;Every page of a website needs the same frame: a title, some styling, a navigation bar, and so on.&lt;br&gt;
Typing that for each page would get old quickly.&lt;br&gt;
So let's write a function that takes the title and the content of a page and wraps them in a frame.&lt;/p&gt;

&lt;p&gt;Add this above &lt;code&gt;handler&lt;/code&gt; (Clojure reads a file from top to bottom, so a function has to be defined before the code that uses it):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;style&amp;gt;body{font-family:sans-serif;max-width:600px;margin:40px auto;padding:0 20px}"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"nav a{margin-right:12px}&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;nav&amp;gt;&amp;lt;a href=\"/\"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;a href=\"/about\"&amp;gt;About&amp;lt;/a&amp;gt;&amp;lt;/nav&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;page&lt;/code&gt; receives two things, &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt;, the same way &lt;code&gt;handler&lt;/code&gt; receives &lt;code&gt;req&lt;/code&gt;.&lt;br&gt;
Most of the text inside it is the frame itself. The &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; lines are decoration, so you don't need to understand them yet. Just type them in.&lt;/p&gt;

&lt;p&gt;Two things to notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;str&lt;/code&gt; joins things together into one piece of text. &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt; get dropped between the other pieces.&lt;/li&gt;
&lt;li&gt;To put a double quote &lt;em&gt;inside&lt;/em&gt; a piece of text you write &lt;code&gt;\"&lt;/code&gt;, which is why &lt;code&gt;href=\"/\"&lt;/code&gt; looks so busy. The backslash means "literally print this next character, I'm not trying to end the text."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now use &lt;code&gt;page&lt;/code&gt; to write two pages. Each one is a function with no inputs (that's the empty &lt;code&gt;[]&lt;/code&gt;), that returns HTML text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;home-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Home"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Hi, I'm Carvalho&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;Welcome to my corner of the internet.&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;ul&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;li&amp;gt;&amp;lt;a href=\"https://github.com\"&amp;gt;GitHub&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/ul&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;about-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"About"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;About Me&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;I'm learning Clojure and building my first website!&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;str&lt;/code&gt; shows up again here, joining the lines of each body into one piece of text before &lt;code&gt;page&lt;/code&gt; wraps it.&lt;/p&gt;

&lt;p&gt;Put your real name and real links in &lt;code&gt;home-page&lt;/code&gt;.&lt;br&gt;
Nothing changes in the browser yet. In the next step we'll connect these pages to addresses so you can see them.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Show the right page
&lt;/h2&gt;

&lt;p&gt;You have two pages and one &lt;code&gt;handler&lt;/code&gt;. The handler needs to look at &lt;code&gt;:uri&lt;/code&gt;, which you saw in Step 1, and choose what page to show.&lt;/p&gt;

&lt;p&gt;Replace &lt;code&gt;handler&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
              &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;)}))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;(:uri req)&lt;/code&gt; looks up the key &lt;code&gt;:uri&lt;/code&gt; in the request map. (It's a Clojure shortcut: a keyword in the first position looks itself up in the map that follows.)&lt;br&gt;
&lt;code&gt;case&lt;/code&gt; then picks the option that matches that value: &lt;code&gt;"/"&lt;/code&gt; gets the home page and &lt;code&gt;"/about"&lt;/code&gt; gets the about page.&lt;/p&gt;

&lt;p&gt;Restart and visit &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;/about&lt;/code&gt;. You have a two-page website, with a navigation bar that works.&lt;/p&gt;

&lt;p&gt;It works, but look at the two response maps: they're identical except for the &lt;code&gt;:body&lt;/code&gt;.&lt;br&gt;
Add a third page and you'd copy it a third time, and a fourth, and so on.&lt;br&gt;
Whenever you catch yourself repeating the same work, consider moving it to a function so it can be reused.&lt;br&gt;
Here's a small helper function that builds the response map.&lt;br&gt;
The only thing that changes between pages, the body, becomes its input.&lt;br&gt;
Add it above &lt;code&gt;handler&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;handler&lt;/code&gt; can shrink to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart and visit both pages again: nothing changed for the visitor, and your code is less repetitive.&lt;br&gt;
The status is a parameter too, which is going to be handy in the next step.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; your website now has more than one page.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Step 5: Handle pages that don't exist
&lt;/h2&gt;

&lt;p&gt;Visit &lt;a href="http://localhost:8080/nothing-here" rel="noopener noreferrer"&gt;http://localhost:8080/nothing-here&lt;/a&gt;.&lt;br&gt;
Instead of something friendly, the browser shows &lt;code&gt;No matching clause: /nothing-here&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;case&lt;/code&gt; needs a match, and there wasn't one, so the server gave up (and answered with status &lt;code&gt;500&lt;/code&gt;, the web's code for "something broke on the server").&lt;/p&gt;

&lt;p&gt;The fix is a catch-all as the last option: a page for "I don't know that one", with status &lt;code&gt;404&lt;/code&gt;, the web's code for "not found".&lt;br&gt;
Add &lt;code&gt;not-found-page&lt;/code&gt; above &lt;code&gt;handler&lt;/code&gt;, and replace &lt;code&gt;handler&lt;/code&gt; with the new version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;not-found-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Not Found"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;404 - Page Not Found&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;not-found-page&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at the last line of &lt;code&gt;case&lt;/code&gt;: it has only a result, with no match value in front of it.&lt;br&gt;
&lt;code&gt;case&lt;/code&gt; treats that as the default, the answer when nothing else matched.&lt;/p&gt;

&lt;p&gt;Restart and try &lt;code&gt;/nothing-here&lt;/code&gt; again.&lt;/p&gt;

&lt;p&gt;The 404 page looks like any other page, so how do you know the status really is &lt;code&gt;404&lt;/code&gt;? Your browser keeps track.&lt;br&gt;
Right-click the page, choose &lt;strong&gt;Inspect&lt;/strong&gt;, open the &lt;strong&gt;Network&lt;/strong&gt; tab and reload. The &lt;strong&gt;Status&lt;/strong&gt; column shows &lt;code&gt;404&lt;/code&gt; for &lt;code&gt;/nothing-here&lt;/code&gt;, and &lt;code&gt;200&lt;/code&gt; for &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;/about&lt;/code&gt;.&lt;br&gt;
Status codes are mostly for machines, like browsers and search engines, which need to know what happened without reading the page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; your website now answers every address: with a page when it knows one, and with a friendly 404 when it doesn't.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  The whole file
&lt;/h2&gt;

&lt;p&gt;Here is the full &lt;code&gt;src/app/core.clj&lt;/code&gt; at this point. If something isn't working, compare yours to this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:gen-class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/title&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;style&amp;gt;body{font-family:sans-serif;max-width:600px;margin:40px auto;padding:0 20px}"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"nav a{margin-right:12px}&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;nav&amp;gt;&amp;lt;a href=\"/\"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;a href=\"/about\"&amp;gt;About&amp;lt;/a&amp;gt;&amp;lt;/nav&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;home-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Home"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;Hi, I'm Carvalho&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;Welcome to my corner of the internet.&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;ul&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;li&amp;gt;&amp;lt;a href=\"https://github.com\"&amp;gt;GitHub&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;/ul&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;about-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"About"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;About Me&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
             &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;p&amp;gt;I'm learning Clojure and building my first website!&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;not-found-page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Not Found"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;h1&amp;gt;404 - Page Not Found&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/html"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;home-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;about-page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;html-response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;not-found-page&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Integer/parseInt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;System/getenv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"8080"&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;})))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy it
&lt;/h2&gt;

&lt;p&gt;Same command as in Part 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vercel deploy &lt;span class="nt"&gt;--prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vercel remembers your project from last time, so it shouldn't ask you the setup questions again.&lt;br&gt;
Open the link and click around. Visit &lt;code&gt;/about&lt;/code&gt;, and then &lt;code&gt;/nothing-here&lt;/code&gt; to see your 404 page live.&lt;br&gt;
You didn't need to change &lt;code&gt;Dockerfile.vercel&lt;/code&gt; from Part 2: it copies the whole &lt;code&gt;src&lt;/code&gt; folder, so your new code goes along automatically.&lt;br&gt;
Your website is getting more interesting!&lt;/p&gt;

&lt;h2&gt;
  
  
  If something went wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The browser shows old content&lt;/strong&gt;: the running program still has the old code. Stop the server with &lt;code&gt;Ctrl+C&lt;/code&gt;, start it again, and refresh.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Unable to resolve symbol: html-response&lt;/code&gt;&lt;/strong&gt; (or &lt;code&gt;home-page&lt;/code&gt;, &lt;code&gt;page&lt;/code&gt;...): Clojure reads the file from top to bottom, so a function has to be defined &lt;em&gt;above&lt;/em&gt; the code that uses it. Move it above &lt;code&gt;handler&lt;/code&gt;, and check the spelling of the name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Syntax error reading source&lt;/code&gt; or &lt;code&gt;Unmatched delimiter&lt;/code&gt;&lt;/strong&gt;: a parenthesis is missing or extra. Remember the "Break it on purpose" section in Part 1: the line number in the error is where to start looking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The page shows &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; and other tags as text&lt;/strong&gt;: the &lt;code&gt;Content-Type&lt;/code&gt; is still &lt;code&gt;text/plain&lt;/code&gt;. It has to be &lt;code&gt;text/html&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;No matching clause: /something&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;case&lt;/code&gt; didn't find a match and has no default. Add the last line from Step 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The request is a map too: &lt;code&gt;:uri&lt;/code&gt; tells &lt;code&gt;handler&lt;/code&gt; which page the visitor asked for, and &lt;code&gt;:query-string&lt;/code&gt; holds what comes after the &lt;code&gt;?&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Content-Type&lt;/code&gt; tells the browser how to read the response. &lt;code&gt;text/html&lt;/code&gt; makes it interpret the HTML tags.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;str&lt;/code&gt; joins pieces of text, and &lt;code&gt;page&lt;/code&gt; uses it to wrap any content in the same frame (title, styling, and navigation), so every page of your website looks similar.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;home-page&lt;/code&gt;, &lt;code&gt;about-page&lt;/code&gt; and &lt;code&gt;not-found-page&lt;/code&gt; are functions that return HTML text, and &lt;code&gt;handler&lt;/code&gt; uses &lt;code&gt;case&lt;/code&gt; to pick one based on &lt;code&gt;:uri&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When you catch yourself repeating the same work, move it into a function. &lt;code&gt;html-response&lt;/code&gt; did that for the response map.&lt;/li&gt;
&lt;li&gt;A function has to be defined above the code that uses it.&lt;/li&gt;
&lt;li&gt;Status codes are part of the response: &lt;code&gt;200&lt;/code&gt; means OK and &lt;code&gt;404&lt;/code&gt; means not found. Without a default, &lt;code&gt;case&lt;/code&gt; fails and the server answers with a &lt;code&gt;500&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;In the next part we'll make a page that responds to what a user types, and you'll finally put &lt;code&gt;:query-string&lt;/code&gt; from Step 1 to work.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>clojure</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deploy your first Clojure website to Vercel (beginner-friendly)</title>
      <dc:creator>Thiago Carvalho</dc:creator>
      <pubDate>Mon, 26 Oct 2026 03:00:11 +0000</pubDate>
      <link>https://dev.to/thiagooak/learning-clojure-from-scratch-part-2-put-it-on-the-internet-55pb</link>
      <guid>https://dev.to/thiagooak/learning-clojure-from-scratch-part-2-put-it-on-the-internet-55pb</guid>
      <description>&lt;p&gt;This is part two of a series teaching Clojure to people with little or no programming experience.&lt;br&gt;
In Part 1 you built a small website and ran it on your computer.&lt;/p&gt;

&lt;p&gt;Right now the only person who can see your website is you.&lt;br&gt;
In this part we'll fix that.&lt;br&gt;
By the end you'll have a link you can open on your phone and send to a friend.&lt;/p&gt;

&lt;p&gt;The server code barely changes. Most of the work is teaching the &lt;em&gt;outside world&lt;/em&gt; how to run it.&lt;/p&gt;
&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;p&gt;On top of what you have from Part 1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A free &lt;a href="https://vercel.com/signup" rel="noopener noreferrer"&gt;Vercel account&lt;/a&gt;. Vercel is where your website will run.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;Node.js installed&lt;/a&gt; on your computer. We need it to install and run Vercel's command line tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To check that Node is installed, run &lt;code&gt;npm --version&lt;/code&gt; in the terminal.&lt;/p&gt;

&lt;p&gt;Open your &lt;code&gt;my-site&lt;/code&gt; folder in VS Code and open a terminal (&lt;strong&gt;Terminal&lt;/strong&gt; &amp;gt; &lt;strong&gt;New Terminal&lt;/strong&gt;), just like last time.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why a few things have to change
&lt;/h2&gt;

&lt;p&gt;On your computer, you run a command and the program runs.&lt;br&gt;
When someone else's computer runs it, three things need to be true:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The program has to listen on whichever port &lt;em&gt;they&lt;/em&gt; tell it to, not the one you hard-coded.&lt;/li&gt;
&lt;li&gt;The program has to be bundled into a single file, so it can be copied around.&lt;/li&gt;
&lt;li&gt;They need a recipe that says how to build and start it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll take these one at a time, and after each one you can check that your website still works.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Let the outside world choose the port
&lt;/h2&gt;

&lt;p&gt;In Part 1, you hard-coded the port as &lt;code&gt;8080&lt;/code&gt; (&lt;code&gt;(http/run-server handler {:port 8080})&lt;/code&gt;). Vercel requires that your program use a port they define in an &lt;em&gt;environment variable&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Environment variables live outside your code, and you can look them up by name.&lt;br&gt;
The one you'll use is called &lt;code&gt;PORT&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Replace &lt;code&gt;-main&lt;/code&gt; in &lt;code&gt;src/app/core.clj&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Integer/parseInt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;System/getenv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"8080"&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;})))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it from the inside out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(System/getenv "PORT")&lt;/code&gt; asks "is there an environment variable called &lt;code&gt;PORT&lt;/code&gt;?" You get its value, or &lt;code&gt;nil&lt;/code&gt; (nothing) if there isn't one.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(or ... "8080")&lt;/code&gt; means "use &lt;code&gt;PORT&lt;/code&gt;, or (if &lt;code&gt;PORT&lt;/code&gt; is nil) use &lt;code&gt;"8080"&lt;/code&gt; instead".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(Integer/parseInt ...)&lt;/code&gt; turns the text &lt;code&gt;"8080"&lt;/code&gt; into the number &lt;code&gt;8080&lt;/code&gt;. Environment variables are always text, so we have to convert.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; gives a name to a value, so &lt;code&gt;port&lt;/code&gt; refers to either the value of &lt;code&gt;PORT&lt;/code&gt; or &lt;code&gt;8080&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run it (&lt;code&gt;clojure -M:run&lt;/code&gt;) and open &lt;code&gt;localhost:8080&lt;/code&gt;. Nothing changed, because &lt;code&gt;PORT&lt;/code&gt; was never defined.&lt;/p&gt;

&lt;p&gt;Now stop the server (&lt;code&gt;Ctrl+C&lt;/code&gt;) and start it with a port of your choosing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3000 clojure &lt;span class="nt"&gt;-M&lt;/span&gt;:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(On Windows PowerShell this would be &lt;code&gt;$env:PORT=3000; clojure -M:run&lt;/code&gt;.)&lt;/p&gt;

&lt;p&gt;The terminal now says &lt;code&gt;Server running on port 3000&lt;/code&gt;.&lt;br&gt;
Your website is now running at &lt;code&gt;localhost:3000&lt;/code&gt;. It adapts to its environment.&lt;/p&gt;

&lt;p&gt;Stop the server again with &lt;code&gt;Ctrl+C&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Bundle it into one file
&lt;/h2&gt;

&lt;p&gt;Right now your program is a folder of source files plus a set of libraries that &lt;code&gt;clojure&lt;/code&gt; downloads on demand.&lt;br&gt;
To copy it to another machine, we want a single file with everything inside.&lt;br&gt;
In the Java world that file is called a &lt;em&gt;jar&lt;/em&gt;, and one that contains everything is called an &lt;em&gt;uberjar&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We need three changes to create an &lt;em&gt;uberjar&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, add &lt;code&gt;(:gen-class)&lt;/code&gt; to the &lt;code&gt;ns&lt;/code&gt; at the top of &lt;code&gt;src/app/core.clj&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:gen-class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Java that this file can be the starting point of a packaged program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, replace &lt;code&gt;deps.edn&lt;/code&gt; with this. The only new part is the &lt;code&gt;:build&lt;/code&gt; alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:paths&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;org.clojure/clojure&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:mvn/version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"1.12.0"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;http-kit/http-kit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:mvn/version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"2.8.0"&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:aliases&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:main-opts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"-m"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"app.core"&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="no"&gt;:build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;io.github.clojure/tools.build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:mvn/version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"0.10.5"&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="no"&gt;:ns-default&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;}}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;:run&lt;/code&gt; is still a shortcut for starting the program. &lt;code&gt;:build&lt;/code&gt; is a shortcut for a tool, &lt;code&gt;tools.build&lt;/code&gt;, that knows how to bundle a program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third&lt;/strong&gt;, create a file called &lt;code&gt;build.clj&lt;/code&gt; in the root of the project (next to &lt;code&gt;deps.edn&lt;/code&gt;, not inside &lt;code&gt;src&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;clojure.tools.build.api&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;class-dir&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"target/classes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;uber-file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"target/app.jar"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;basis&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b/create-basis&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:project&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"deps.edn"&lt;/span&gt;&lt;span class="p"&gt;})))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;uber&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b/delete&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b/copy-dir&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:src-dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:target-dir&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;class-dir&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b/compile-clj&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:basis&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;basis&lt;/span&gt;&lt;span class="w"&gt;
                  &lt;/span&gt;&lt;span class="no"&gt;:src-dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
                  &lt;/span&gt;&lt;span class="no"&gt;:class-dir&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;class-dir&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b/uber&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:class-dir&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;class-dir&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="no"&gt;:uber-file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;uber-file&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="no"&gt;:basis&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;basis&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="no"&gt;:main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;'app.core&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a program whose job is to build your program.&lt;br&gt;
Read the steps in &lt;code&gt;uber&lt;/code&gt; in order and you'll get the idea: delete the old &lt;code&gt;target&lt;/code&gt; folder, copy the source in, compile it, and pack it together with all the libraries into &lt;code&gt;target/app.jar&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now build it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure &lt;span class="nt"&gt;-T&lt;/span&gt;:build uber
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first time, Clojure downloads the build tool, so it can take a minute. It prints nothing when it succeeds. Check that &lt;code&gt;target/app.jar&lt;/code&gt; appeared in the file explorer.&lt;/p&gt;

&lt;p&gt;Then run the jar directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java &lt;span class="nt"&gt;-jar&lt;/span&gt; target/app.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;localhost:8080&lt;/code&gt;. You should see &lt;code&gt;Hello, World!&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; this is exactly what Vercel will do with your project. If it works here, the hard part is done.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Stop the server with &lt;code&gt;Ctrl+C&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Write the recipe
&lt;/h2&gt;

&lt;p&gt;Create a file called &lt;code&gt;Dockerfile.vercel&lt;/code&gt; in the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;clojure:temurin-21-tools-deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; deps.edn build.clj .&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; src src&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;clojure &lt;span class="nt"&gt;-T&lt;/span&gt;:build uber

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; eclipse-temurin:21-jre-alpine&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=build /app/target/app.jar /app.jar&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["/opt/java/openjdk/bin/java", "-jar", "/app.jar"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the recipe Vercel follows to build and run your program.&lt;br&gt;
Vercel looks for a file with exactly this name, and runs the result.&lt;/p&gt;

&lt;p&gt;You don't need to understand the details of this file right now. Its shape is what matters. It has two parts, each starting with &lt;code&gt;FROM&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build.&lt;/strong&gt; Start from a machine that has Clojure installed, copy in &lt;code&gt;deps.edn&lt;/code&gt;, &lt;code&gt;build.clj&lt;/code&gt; and &lt;code&gt;src&lt;/code&gt;, and run: &lt;code&gt;clojure -T:build uber&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run.&lt;/strong&gt; Start from a much smaller machine that has only Java, copy in &lt;code&gt;app.jar&lt;/code&gt;, and start it using &lt;code&gt;java -jar app.jar&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Step 4: Leave some things out
&lt;/h2&gt;

&lt;p&gt;Create two more files in the root of the project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.dockerignore&lt;/code&gt; lists things that shouldn't be sent to the build machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.git
.gitignore
target
.cpcache
README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;.gitignore&lt;/code&gt; lists things you don't want to save into version control (when you start using Git, it will skip these):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.cpcache/
.clj-kondo/
.lsp/
target/
.vercel/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Write some documentation
&lt;/h2&gt;

&lt;p&gt;Add one more file called &lt;code&gt;README.md&lt;/code&gt; so future-you remembers what this folder is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# My Clojure website&lt;/span&gt;

Built following the "Learning Clojure from Scratch" series.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your project should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-site/
  .dockerignore
  .gitignore
  Dockerfile.vercel
  README.md
  build.clj
  deps.edn
  src/
    app/
      core.clj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you compare it with &lt;a href="https://github.com/thiagooak/vercel-clojure" rel="noopener noreferrer"&gt;&lt;code&gt;vercel-clojure&lt;/code&gt;&lt;/a&gt;, the template this series is based on, you'll find the same files. But you wrote them yourself, and you know why each one is there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Deploy
&lt;/h2&gt;

&lt;p&gt;Install Vercel's command line tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Log in. This opens your browser to confirm who you are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vercel login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your browser, Vercel asks you to authorize your device. Once you do (you'll see a message like "Congratulations! You are now signed in."), run the command below to deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vercel deploy &lt;span class="nt"&gt;--prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first time, Vercel asks a few questions about your project. When asked "Which project?", select "Create a new project". For the other questions, the suggested answers are usually fine. After you answer all of the questions, Vercel will build and deploy your website.&lt;/p&gt;

&lt;p&gt;When it finishes you'll get a link that ends in &lt;code&gt;vercel.app&lt;/code&gt;.&lt;br&gt;
Open it. You should see &lt;code&gt;Hello, World!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's your program, running in the cloud, reachable from anywhere in the world.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; open the link on your phone or another computer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  If something went wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;vercel: command not found&lt;/code&gt;&lt;/strong&gt;: the install in Step 6 didn't finish, or your terminal needs to be reopened.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The build fails on Vercel&lt;/strong&gt;: the output in the terminal shows the failing line. The most common cause is a typo in &lt;code&gt;build.clj&lt;/code&gt; or &lt;code&gt;Dockerfile.vercel&lt;/code&gt;. If &lt;code&gt;clojure -T:build uber&lt;/code&gt; works on your computer, the build step should work on Vercel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The link shows an error page&lt;/strong&gt;: first check that &lt;code&gt;java -jar target/app.jar&lt;/code&gt; works locally. If it does, run &lt;code&gt;vercel logs&lt;/code&gt; with your deployment's link to see what your program printed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The link asks you to log in to Vercel&lt;/strong&gt;: Vercel can protect some of the links it creates so only you can see them. Open the link labelled &lt;em&gt;Production&lt;/em&gt; in the output of &lt;code&gt;vercel deploy --prod&lt;/code&gt;, or find your project in the Vercel dashboard and use its production domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your program now reads its port from an environment variable (&lt;code&gt;PORT&lt;/code&gt;) and falls back to &lt;code&gt;8080&lt;/code&gt; when there isn't one, so the same code works on your computer and on Vercel.&lt;/li&gt;
&lt;li&gt;An &lt;em&gt;uberjar&lt;/em&gt; is a single file with your code and all of its libraries. &lt;code&gt;clojure -T:build uber&lt;/code&gt; creates it and &lt;code&gt;java -jar target/app.jar&lt;/code&gt; runs it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build.clj&lt;/code&gt; is a small program whose job is to build your program, and the &lt;code&gt;:build&lt;/code&gt; alias in &lt;code&gt;deps.edn&lt;/code&gt; is how you call it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Dockerfile.vercel&lt;/code&gt; is the recipe Vercel follows: one stage builds the jar, the other runs it.&lt;/li&gt;
&lt;li&gt;Deploying means giving another computer a recipe and the files it needs. &lt;code&gt;vercel deploy --prod&lt;/code&gt; does that, and the result is a link anyone on the internet can open.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;We'll stop saying "Hello, World!" and put your own words and pages on the website.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>vercel</category>
    </item>
    <item>
      <title>Learn Clojure from zero: build a tiny website in 15 minutes</title>
      <dc:creator>Thiago Carvalho</dc:creator>
      <pubDate>Mon, 26 Oct 2026 02:56:32 +0000</pubDate>
      <link>https://dev.to/thiagooak/learning-clojure-from-scratch-part-1-hello-world-5fhj</link>
      <guid>https://dev.to/thiagooak/learning-clojure-from-scratch-part-1-hello-world-5fhj</guid>
      <description>&lt;p&gt;This is part one of a series of blog posts that &lt;del&gt;tries to&lt;/del&gt; teaches you Clojure from scratch.&lt;br&gt;
It assumes that you have little or no experience with programming.&lt;/p&gt;

&lt;p&gt;By the end of the series you'll have your own Clojure website deployed to production:&lt;br&gt;
a homepage, an interactive page, and a blog.&lt;/p&gt;

&lt;p&gt;Some of it will be hard, and you won't understand everything we do to get there. Try to trust the process.&lt;br&gt;
My primary goal is to help you experience success early (in the form of having your own website)&lt;br&gt;
in the hope that it motivates you to continue your learning journey.&lt;br&gt;
If you are curious and persistent, you should be able to complete this. Good luck!&lt;/p&gt;

&lt;p&gt;In this first part we'll build a very small program and run it.&lt;/p&gt;
&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://clojure.org/guides/install_clojure" rel="noopener noreferrer"&gt;Clojure installed&lt;/a&gt; on your computer&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;Visual Studio Code installed&lt;/a&gt; on your computer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To check that Clojure is installed, open a terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it prints a version number, you're ready.&lt;/p&gt;

&lt;p&gt;Clojure runs on the JVM (Java Virtual Machine), and the installation guide walks you through getting that too, so there is nothing extra to download if the command above works.&lt;br&gt;
This series is written with macOS and Linux terminals in mind, but Windows should work too.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a project folder
&lt;/h2&gt;

&lt;p&gt;Create an empty folder on your computer and call it &lt;code&gt;my-site&lt;/code&gt;.&lt;br&gt;
Open Visual Studio Code, click &lt;strong&gt;File&lt;/strong&gt; &amp;gt; &lt;strong&gt;Open Folder&lt;/strong&gt;, and choose &lt;code&gt;my-site&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You'll see an empty file explorer on the left.&lt;br&gt;
Everything you make in this series will live here.&lt;/p&gt;

&lt;p&gt;Now click &lt;strong&gt;Terminal&lt;/strong&gt; &amp;gt; &lt;strong&gt;New Terminal&lt;/strong&gt;.&lt;br&gt;
A panel opens at the bottom of the window.&lt;br&gt;
A terminal is a place where you give your computer instructions by typing them.&lt;br&gt;
This one starts "inside" your &lt;code&gt;my-site&lt;/code&gt; folder, which is exactly where you want it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Optional:&lt;/strong&gt; open the Extensions panel (the squares icon on the left), search for &lt;strong&gt;Calva&lt;/strong&gt;, and install it. It will make it easier to work with Clojure files and will allow you to do REPL-driven development in the future.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Step 1: Tell Clojure about your project
&lt;/h2&gt;

&lt;p&gt;Create a new file called &lt;code&gt;deps.edn&lt;/code&gt; in the root of your project&lt;br&gt;
(hover over the file explorer and click the "New File" icon).&lt;br&gt;
Paste or type this in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:paths&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;org.clojure/clojure&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:mvn/version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"1.12.0"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;http-kit/http-kit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:mvn/version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"2.8.0"&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="no"&gt;:aliases&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:main-opts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"-m"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"app.core"&lt;/span&gt;&lt;span class="p"&gt;]}}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to understand all of this yet, but here is a quick tour:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:paths ["src"]&lt;/code&gt; says "my code lives in a folder called &lt;code&gt;src&lt;/code&gt;".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:deps&lt;/code&gt; lists the libraries this project uses. Clojure itself is one of them.
The other is &lt;a href="https://github.com/http-kit/http-kit" rel="noopener noreferrer"&gt;http-kit&lt;/a&gt;, a library that speaks HTTP, the language of web browsers.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:aliases&lt;/code&gt; defines shortcuts. &lt;code&gt;:run&lt;/code&gt; is a shortcut that means "start the program whose entry point is called &lt;code&gt;app.core&lt;/code&gt;".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole file is a &lt;em&gt;map&lt;/em&gt;: a collection of keys (the keywords starting with &lt;code&gt;:&lt;/code&gt;) and the values that go with them.&lt;/p&gt;

&lt;p&gt;Make sure to save the file before moving to the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Write the program
&lt;/h2&gt;

&lt;p&gt;Create a new file at &lt;code&gt;src/app/core.clj&lt;/code&gt;.&lt;br&gt;
That's a folder called &lt;code&gt;src&lt;/code&gt; (src is short for source), with a folder called &lt;code&gt;app&lt;/code&gt; inside it, with a file called &lt;code&gt;core.clj&lt;/code&gt; inside that.&lt;br&gt;
(If you type &lt;code&gt;src/app/core.clj&lt;/code&gt; as the file name, VS Code will create the folders for you.)&lt;/p&gt;

&lt;p&gt;The name &lt;code&gt;app.core&lt;/code&gt; in &lt;code&gt;deps.edn&lt;/code&gt; matches this path: &lt;code&gt;src/app/core.clj&lt;/code&gt;.&lt;br&gt;
Clojure uses the folders and file name to find your code.&lt;/p&gt;

&lt;p&gt;One thing to know before we start: Clojure uses lots of parentheses.&lt;br&gt;
Almost everything is written as &lt;code&gt;(something and-then-its-arguments)&lt;/code&gt;:&lt;br&gt;
the first word says what to do, and the rest is what to do it with.&lt;br&gt;
For example, &lt;code&gt;(println "Hello")&lt;/code&gt; means "print the text Hello".&lt;br&gt;
Every &lt;code&gt;(&lt;/code&gt; needs a matching &lt;code&gt;)&lt;/code&gt;, and the same goes for &lt;code&gt;[&lt;/code&gt; with &lt;code&gt;]&lt;/code&gt; and &lt;code&gt;{&lt;/code&gt; with &lt;code&gt;}&lt;/code&gt;.&lt;br&gt;
VS Code highlights matching pairs as you type, and if you lose one, Clojure will tell you. We'll try that on purpose near the end.&lt;/p&gt;

&lt;p&gt;We'll write the file in three small pieces.&lt;/p&gt;
&lt;h3&gt;
  
  
  Piece 1: Define a namespace and require some code
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;ns&lt;/code&gt; is short for &lt;em&gt;namespace&lt;/em&gt;.&lt;br&gt;
The first line of your Clojure file defines the namespace you are working on (&lt;code&gt;app.core&lt;/code&gt;) and the code it needs from other places in order to work.&lt;br&gt;
Here we require &lt;code&gt;org.httpkit.server&lt;/code&gt; from http-kit and give it the nickname &lt;code&gt;http&lt;/code&gt; so we don't have to type the long name every time.&lt;/p&gt;
&lt;h3&gt;
  
  
  Piece 2: Handle requests
&lt;/h3&gt;

&lt;p&gt;Add this at the bottom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A website is like a conversation: a browser sends a &lt;em&gt;request&lt;/em&gt; and the server sends back a &lt;em&gt;response&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   browser                        your program
  ---------                    ------------------
  GET /  ---- request ------&amp;gt;  handler
         &amp;lt;--- response ------  {:status 200 ...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;handler&lt;/code&gt; is the function that &lt;strong&gt;handles&lt;/strong&gt; what to send back.&lt;br&gt;
A &lt;em&gt;function&lt;/em&gt; is a named piece of code that takes something in, does some work, and gives something back.&lt;br&gt;
Here, &lt;code&gt;handler&lt;/code&gt; takes in the request and gives back the response.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;defn&lt;/code&gt; defines a function. Here you named it &lt;code&gt;handler&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[_req]&lt;/code&gt; is the thing the function receives: the request from the browser.
The leading underscore is a convention that means "I'm not using this yet".&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;{...}&lt;/code&gt; is a map that defines the response: &lt;code&gt;:status&lt;/code&gt; is a code (200 means "OK"), &lt;code&gt;:headers&lt;/code&gt; describes the format of the response, and &lt;code&gt;:body&lt;/code&gt; is what shows up on the screen.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that in Clojure, calling a function returns whatever its last expression evaluates to. &lt;code&gt;handler&lt;/code&gt; returns the map with &lt;code&gt;:status&lt;/code&gt;, &lt;code&gt;:headers&lt;/code&gt; and &lt;code&gt;:body&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Piece 3: Create a main function and start the server
&lt;/h3&gt;

&lt;p&gt;Add this at the bottom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port 8080"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-main&lt;/code&gt; is the function that runs when you start your program.&lt;br&gt;
It prints a message, then starts a server with your &lt;code&gt;handler&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;amp; _args&lt;/code&gt; is for words typed after the program's name on the terminal. We're not using any, so ignore it for now.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;8080&lt;/code&gt; is a &lt;em&gt;port&lt;/em&gt;, which you can think of as a numbered door on your computer.&lt;br&gt;
Browsers will knock on door 8080 to talk to your program.&lt;/p&gt;

&lt;p&gt;Here is the complete file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;app.core&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;:require&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;org.httpkit.server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;:as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_req&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:status&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:headers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="no"&gt;:body&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;-main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Server running on port 8080"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;http/run-server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;:port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save it. Your project should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-site/
  deps.edn
  src/
    app/
      core.clj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run it
&lt;/h2&gt;

&lt;p&gt;In the terminal at the bottom of VS Code, type this and hit enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clojure &lt;span class="nt"&gt;-M&lt;/span&gt;:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first time, Clojure downloads the libraries from &lt;code&gt;deps.edn&lt;/code&gt;. It can take a minute.&lt;br&gt;
When it's done you'll see the message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server running on port 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terminal now looks stuck, with no prompt coming back. That's correct: your server is running and waiting for visitors.&lt;/p&gt;

&lt;p&gt;Open &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; in your browser.&lt;br&gt;
&lt;code&gt;localhost&lt;/code&gt; is a name that basically means "this computer".&lt;br&gt;
You should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Checkpoint:&lt;/strong&gt; you just wrote a program that serves a web page. It works only on your computer, but you created a real (and very simple) web page!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Change something
&lt;/h2&gt;

&lt;p&gt;Go back to &lt;code&gt;src/app/core.clj&lt;/code&gt; and change the body from &lt;code&gt;"Hello, World!"&lt;/code&gt; to &lt;code&gt;"Hello, Clojure!"&lt;/code&gt;. Save the file and refresh your browser.&lt;/p&gt;

&lt;p&gt;Nothing changed. That's expected: the running program loaded the old code and doesn't know that the file changed.&lt;br&gt;
Go to the terminal, press &lt;code&gt;Ctrl+C&lt;/code&gt; to stop the server, then run &lt;code&gt;clojure -M:run&lt;/code&gt; again and refresh the browser.&lt;/p&gt;

&lt;p&gt;This is the rhythm for the next few parts: &lt;strong&gt;edit, stop, start, refresh&lt;/strong&gt;.&lt;br&gt;
(Clojure has a smarter way of working called REPL-driven development. We'll start using it in a future post.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Break it on purpose
&lt;/h3&gt;

&lt;p&gt;Reading errors is a good portion of programming, and it's easier when you know what broke. To get some practice, delete the very last character of the &lt;code&gt;:body&lt;/code&gt; line (the &lt;code&gt;)&lt;/code&gt; right after the &lt;code&gt;}&lt;/code&gt;), save, stop the server, and start it again.&lt;/p&gt;

&lt;p&gt;You'll get an error that starts with &lt;code&gt;Syntax error reading source&lt;/code&gt; and says &lt;code&gt;EOF while reading, starting at line 4&lt;/code&gt;.&lt;br&gt;
It's Clojure telling you "I reached the end of the file (EOF) and something that opened on line 4 was never closed".&lt;br&gt;
Line 4 is where &lt;code&gt;handler&lt;/code&gt; begins, so that's the place to look.&lt;br&gt;
Put the &lt;code&gt;)&lt;/code&gt; back, restart, and you're back in business.&lt;/p&gt;

&lt;p&gt;When you see a wall of error text, don't panic. The useful part is usually in the first or second line.&lt;/p&gt;

&lt;h2&gt;
  
  
  If something went wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;clojure: command not found&lt;/code&gt;&lt;/strong&gt;: Clojure isn't installed yet, or the terminal was opened before the install finished. Close VS Code, reopen it, and try again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Address already in use&lt;/code&gt;&lt;/strong&gt;: another program, or an earlier run of this one, is using port 8080. You'll still see &lt;code&gt;Server running on port 8080&lt;/code&gt; just before the error, because the message prints before the server tries to claim the port. Find the terminal where it's still running and press &lt;code&gt;Ctrl+C&lt;/code&gt;. Alternatively, change your code to use another port (say 8081).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An error mentioning &lt;code&gt;Could not locate app/core&lt;/code&gt;&lt;/strong&gt;: the file isn't at &lt;code&gt;src/app/core.clj&lt;/code&gt;. Check the folder and file names.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The browser says it can't connect&lt;/strong&gt;: the server isn't running. Look at the terminal for an error, or for the prompt coming back, which means the program exited.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your website works like a conversation: a browser sends a request, and your program sends back a response.&lt;/li&gt;
&lt;li&gt;A function takes something in, does some work, and returns something. &lt;code&gt;handler&lt;/code&gt;, for example, takes the request and gives back a map describing the response.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;deps.edn&lt;/code&gt; says what the project needs and creates aliases (like &lt;code&gt;clojure -M:run&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/app/core.clj&lt;/code&gt; holds the code for your &lt;code&gt;handler&lt;/code&gt; (what to say) and &lt;code&gt;-main&lt;/code&gt; (the starting point).&lt;/li&gt;
&lt;li&gt;An error message is Clojure telling you where it got lost. Start reading the first and second lines before you panic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;In a future blog post we'll make &lt;code&gt;handler&lt;/code&gt; smarter and we'll make a few small changes so the same program can run on someone else's computer via the internet.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Bonus:&lt;/strong&gt; now that you are technically a Clojure developer, why not join the &lt;a href="http://clojurians.net" rel="noopener noreferrer"&gt;Clojurians community on Slack&lt;/a&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>clojure</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
