(def x (cons (list 1 2) (list 3 4))) ; => ((1 2) 3 4)
(class x) ; => clojure.lang.Cons
(list? x) ; => false
(def y (conj (list 3 4) (list 1 2))) ; => ((1 2) 3 4)
(class y) ; => clojure.lang.PersistentList
(list? y) ; => true
````````````````
ソースをみてみる.
``````````````clojure
user=> (source cons)
(def
^{:arglists '([x seq])
:doc "Returns a new seq where x is the first element and seq is the rest."
:added "1.0"
:static true}
cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq))))
```````````````
``````````````clojure
user=> (source conj)
(def
^{:arglists '([coll x] [coll x & xs])
:doc "conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type."
:added "1.0"
:static true}
conj (fn ^:static conj
([coll x] (. clojure.lang.RT (conj coll x)))
([coll x & xs]
(if xs
(recur (conj coll x) (first xs) (next xs))
(conj coll x)))))
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme