Clojure for Beginners: Clojure Namespaces & `require` — Organizing Code Across Files
Video: Clojure Namespaces & `require` — Organizing Code Across Files | Episode 20 by CelesteAI
Watch full page →Clojure Namespaces & `require` — Organizing Code Across Files
Every Clojure file starts with a namespace. A namespace is how Clojure says "this code lives here" — and `require` is how one file reaches into another. In this episode we leave the single-file world behind and build our first real two-file project: `app.core` requiring `app.util`.
Code
(ns app.core
(:require [app.util :as u]
[clojure.string :refer [join]]))
;; Entry point for the project.
;; File path: src/app/core.clj ↔ namespace: app.core
(defn make-card
"Turn a label into a loud, sluggable display card."
[label]
(let [shouted (u/shout label)
slug (u/slugify label)
boxed (u/wrap "*" shouted)]
(join "\n"
[(str "version: " u/version)
(str "label: " shouted)
(str "slug: " slug)
(str "boxed: " boxed)])))
(defn -main
"Run with: clj -M -m app.core (or) clj -M:run"
[& args]
(let [label (or (first args) "the little schemer")]
(println (make-card label))))
Key Points
Watch the video above for a full walkthrough — every keystroke is shown so you can code along.
Student code: GitHub