Back to Blog

Clojure for Beginners: Your First Script — deps.edn & -main

Celest KimCelest Kim

Video: Clojure deps.edn & Your First Script — Phase 1 Finale | Episode 6 by CelesteAI

Watch full page →

Your First Script — From REPL to Project

Time to move from the REPL to a real project. In this episode we create a project with deps.edn, write a namespace with a -main entry point, and run it from the command line.

Project Structure

my-app/
  deps.edn              {:paths ["src"]}
  src/
    hello/
      core.clj           (ns hello.core) + (defn -main ...)

deps.edn

{:paths ["src"]}

src/hello/core.clj

(ns hello.core)

(defn greet [name]
  (str "Hello, " name "!"))

(defn -main [& args]
  (println "Welcome to my first Clojure project!")
  (println (greet "World"))
  (when args
    (println "Arguments:" args)
    (doseq [a args]
      (println (greet a)))))

Run It

# No arguments
clj -M -m hello.core

# With arguments
clj -M -m hello.core Alice Bob

Key Takeaways

  1. deps.edn is the only config file you need. {:paths ["src"]} tells Clojure where source lives.
  2. -main is the entry point. The dash is part of the name. & args captures command-line input.
  3. Namespace maps to file path: dots become slashes, hyphens become underscores in filenames.
  4. Phase 1 is complete! You know the REPL, syntax, values, functions, conditionals, and project structure.

Student code: GitHub