ClojureDocs

Nav

Namespaces

max

clojure.core

Available since 1.0 (source)
  • (max x)
  • (max x y)
  • (max x y & more)
Returns the greatest of the nums.
3 Examples
;; `max` returns the largest of its arguments
user=> (max 1 2 3 4 5)  
5

;; regardless of order of those arguments
user=> (max 5 4 3 2 1)
5

user=> (max 100)
100
;; If elements are already in a sequence, use apply
user=> (apply max [1 2 3 4 3])
4
user=> (apply max '(4 3 5 6 2))
6
user> (reduce max [1 2 3 4 5 6 7 6 5 4 3])
7
See Also

Returns the x for which (k x), a number, is greatest. If there are multiple such xs, the last one...

Returns the least of the nums.

Added by adereth
2 Notes
    By , created 10.5 years ago

    As of 1.6, max's behavior differs when it's passed single / multiple non-numeric arguments:

    (max "foo") ;;=> "foo"
    
    (max "foo" "bar") ;;=> ClassCastException thrown
    
    By , created 6.1 years ago
    ;; Be warned
    user=> (max 1 nil)
    java.lang.NullPointerException