clarify
This commit is contained in:
+23
-9
@@ -263,27 +263,41 @@ nil ; => nil (Null/Nothing)
|
||||
|
||||
;; --- 14. Java Interop ---
|
||||
|
||||
;; Method call
|
||||
;; === Method Calls ===
|
||||
|
||||
;; Direct form: (. object methodName args…)
|
||||
(.toUpperCase "hello") ; => "HELLO"
|
||||
(.substring "hello" 1 3) ; => "el"
|
||||
|
||||
;; Field form: (. object fieldName) — for getters (no args)
|
||||
(. "hello" length) ; => 5
|
||||
(.length "hello") ; => 5
|
||||
(.age alice) ; => 30
|
||||
|
||||
;; Dot-dot (..): chained field access + method call
|
||||
(.. alice email toUpperCase) ; => "ALICE@EXAMPLE.COM"
|
||||
;; Equivalent to: (. (. alice email) toUpperCase)
|
||||
|
||||
;; Static method
|
||||
(System/getProperty "user.name") ; => "ajet"
|
||||
;; === Static Methods ===
|
||||
|
||||
;; Constructor
|
||||
;; (Class/fieldName) or (Class/staticMethod args…)
|
||||
(System/getProperty "user.name") ; => "ajet" (static field/property)
|
||||
(System/getProperty "java.version") ; => "21.0.x" (static method call)
|
||||
|
||||
;; === Constructors ===
|
||||
|
||||
;; (Class.) or (Class. arg1 arg2…)
|
||||
(java.util.Date.) ; => #inst "2026-09-14T..." (current date/time)
|
||||
(java.util.Date. 2024 0 1) ; => #inst "2024-01-01T..."
|
||||
|
||||
;; --- 15. Threading Macros ---
|
||||
|
||||
;; Thread-first (->) — passes result as first arg
|
||||
;; Note: (.method args) inside -> is a method call on the threaded value
|
||||
(-> "hello"
|
||||
(.toUpperCase)
|
||||
(.replace "H" "J")
|
||||
(.toLowerCase)) ; => "jello"
|
||||
(.toUpperCase) ; method call: .toUpperCase on "hello"
|
||||
(.replace "H" "J") ; method call: .replace on "HELLO"
|
||||
(.toLowerCase)) ; method call: .toLowerCase on "JELLO"
|
||||
; => "jello"
|
||||
|
||||
;; Thread-last (->>) — passes result as last arg
|
||||
(->> [1 2 3 4 5]
|
||||
@@ -297,7 +311,7 @@ nil ; => nil (Null/Nothing)
|
||||
(try
|
||||
(/ 1 0)
|
||||
(catch ArithmeticException e
|
||||
(str "Math error: " (.getMessage e)))) ; => "Math error: Divide by zero"
|
||||
(str "Math error: " (.getMessage e)))) ; method call: (.getMessage e) => "Math error: Divide by zero"
|
||||
|
||||
;; assert — throws AssertionError on failure
|
||||
(assert (= 2 (+ 1 1))) ; => nil (assert returns nil on success)
|
||||
|
||||
Reference in New Issue
Block a user