Code · 1 file

Sample Clojure File

Clojure is a Lisp for the JVM with immutable data structures. The Clojure sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

Clojure · 488 B

Sample Clojure file

An idiomatic Clojure example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.clj — first linesClojure
;; Sample Clojure program — samplefiles.com
(ns sample.core)

(def customers
  [{:id 1 :name "Ada" :balance 12500.0}
   {:id 2 :name "Grace" :balance 830.5}
   {:id 3 :name "Linus" :balance 10000.0}])

(defn vip? [c] (>= (:balance c) 10000))

(defn total-balance [cs] (reduce + (map :balance cs)))

(defn -main []
  (doseq [c customers]
    (println (format "%-6s %10.2f %s" (:name c) (:balance c) (if (vip? c) "VIP" ""))))
  (println (format "Total: %.2f" (total-balance customers))))

File details

Size
488 B (488 bytes)
MIME type
text/plain
SHA-256
704e2726f3de0a083854c772ad7a11b995806601b0fe5bb53edc93e3df98ca89
MD5
139f6b449293c1f99c97d9a9ff861fc0

Download from the command line

curl -L -o sample.clj https://files.samplefiles.com/code/clj/sample.clj

Or check the download in your browser with the checksum calculator.