1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;; Comprehensive Clojure Lexer Test
(ns com.example.core
"A comprehensive test namespace."
(:require [clojure.string :as str]
[clojure.set :refer [union intersection]])
(:import [java.util Date Calendar]))
;; Constants and Defs
(def ^:const pi 3.14159)
(def global-config {:env "prod" :retries 3})
;; Function Definition with Docstring and Multi-arity
(defn greet
"Greets the user with a message.
Supports optional title."
([name] (str "Hello, " name "!"))
([name title] (str "Hello, " title " " name "!")))
;; Records and Protocols
(defrecord Person [name age])
(defprotocol Speaker
(speak [this] "Make the object speak"))
(extend-type Person
Speaker
(speak [this] (str (:name this) " says hello.")))
;; Main Function
(defn -main [& args]
(let [users [{:name "Alice" :age 30}
{:name "Bob" :age 25}
{:name "Charlie" :age 35}]
threshold 26
filtered (filter #(> (:age %) threshold) users)
sorted (sort-by :age users)]
(println "Filtered Users:" filtered)
;; Conditionals
(if (> (count users) 0)
(println "Users found")
(println "No users"))
(cond
(< threshold 20) "Low"
(< threshold 30) "Medium"
:else "High")
;; Macros
(when-let [x (first users)]
(println "First user:" x))
;; Collections and Literals
(def my-map {:a 1, :b 2, "c" 3})
(def my-vec [1 2 3 :keyword])
(def my-set #{1 2 3})
(def my-list '(1 2 3))
;; Threading macros
(->> users
(map :age)
(filter even?)
(reduce +))
;; Metadata
(meta #'greet)
;; Java Interop
(.toUpperCase "clojure")
(Date.)
;; Regex
(re-matches #"\d+" "123")
;; Anonymous function syntax
#(+ % 1)
;; Keywords and Symbols
:keyword
::namespaced-keyword
'symbol
;; Numbers
123
-123
123N
1.23
1.23M
1.23e-4
1/3
0xFF
012
2r1010
;; Characters
\a \newline \space \u0041
))
;; Macro Definition
(defmacro unless [test & body]
`(if (not ~test)
(do ~@body)))
;; Comment
(comment
(greet "World")
(speak (->Person "Dave" 40)))