0
votes

I'm having trouble finding where cons has been defined in Clojurescript as it is not there in the ISeq protocol.

https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L616

Is it a compile time or runtime thing?

1

1 Answers

3
votes

https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L3297

(defn cons
  "Returns a new seq where x is the first element and coll is the rest."
  [x coll]
  (cond
    (nil? coll)             (List. nil x nil 1 nil)
    (implements? ISeq coll) (Cons. nil x coll nil)
    :default                (Cons. nil x (seq coll) nil)))

https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L3237

(deftype Cons [meta first rest ^:mutable __hash]
  ASeq
  ISeq
  (-first [coll] first)
  (-rest [coll] (if (nil? rest) () rest)))