Returns a number one greater than num. Does not auto-promote longs, will throw on overflow. See also: inc'
;;increment all the element in a collection (map inc [1 2 3 4 5]) ;;(2 3 4 5 6) return type list (into [] (map inc [1 2 3 4 5])) ;;[2 3 4 5 6] return type vector
;; Careful when using ClojureScript ;; Make sure you're passing a number ;; because JavaScript + also does string concatenation cljs.user=> (inc "1") "11" cljs.user=> (inc 1) 2 ;; Although it's not the case with dec ;; In JavaScript "1" - 1 = 0 cljs.user=> (dec "1") 0 cljs.user=> (dec 1) 0
;; You cannot `inc` a `nil` in Clojure, but you ;; can in ClojureScript ;; Clojure (inc nil) ;;=> NullPointerException ;; ClojureScript (inc nil) ;;=> 1
Returns a number one less than num. Does not auto-promote longs, will throw on overflow. See also:...
Returns a number one greater than num. Supports arbitrary precision. See also: inc
Returns a number one greater than x, a long. Note - uses a primitive operator subject to overflow.
Is the documentation suppose to be: "Returns a number one greater than x." ? If not what is num?
is code "(def i (inc i))" is conflict with the notion of immutable of data in Clojure.
Nope, quite the opposite. "def" defines a var:
user=> (type (def i 1)) clojure.lang.VarA var is one of the 4 types dealing with mutable state (it is not an immutable data structure, like maps, vectors, sets and so on) and it does so following a specific semantic (see http://clojure.org/reference/vars).