1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

consとconjの違い

Last updated at Posted at 2013-08-04
(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)))))
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?