<commit_before>(ns cljs.core
  (:require js/hamt))

;; Core protocols

(defprotocol IEncodeJS
  (-clj->js  [x])
  (-key->js  [x]))

(defprotocol IFn
  (-invoke
    ;; Yay Christmas tree!
    [_]
    [_ a]
    [_ a b]
    [_ a b c]
    [_ a b c d]
    [_ a b c d e]
    [_ a b c d e f]
    [_ a b c d e f g]
    [_ a b c d e f g h]
    [_ a b c d e f g h i]
    [_ a b c d e f g h i j]
    [_ a b c d e f g h i j k]
    [_ a b c d e f g h i j k l]
    [_ a b c d e f g h i j k l m]
    [_ a b c d e f g h i j k l m n]
    [_ a b c d e f g h i j k l m n o]
    [_ a b c d e f g h i j k l m n o p]
    [_ a b c d e f g h i j k l m n o p q]
    [_ a b c d e f g h i j k l m n o p q r]
    [_ a b c d e f g h i j k l m n o p q r s]
    [_ a b c d e f g h i j k l m n o p q r s t]
    [_ a b c d e f g h i j k l m n o p q r s t rest]))

(defprotocol ICollection
  (-conj  [rng o]))

(defprotocol IIndexed
  (-nth [coll n] [coll n not-found]))

(defprotocol ISeqable
  (-seq [o]))

(defprotocol ISequential)

(defprotocol IList)

(defprotocol IReversible
  (-rseq  [coll]))

(defprotocol ISorted
  (-sorted-seq  [coll ascending?])
  (-sorted-seq-from  [coll k ascending?])
  (-entry-key  [coll entry])
  (-comparator  [coll]))

(defprotocol IVector
  (-assoc-n [coll n val]))

(defprotocol IAssociative
  (-contains-key? [coll k])
  (-assoc [coll k v]))

(defprotocol IMap
  (-dissoc [coll k]))

(defprotocol ICounted
  (-count [coll]))

(defprotocol ASeq)

(defprotocol ISeq
    (-first [coll])
    (-rest  [coll]))

(defprotocol INext
  (-next [coll]))

(defprotocol ILookup
  (-lookup [o k] [o k not-found]))

(defprotocol ISet
  (-disjoin [coll v]))

(defprotocol IStack
  (-peek [coll])
  (-pop [coll]))

(defprotocol IReduce
  (-reduce [coll f] [coll f start]))

(defprotocol IPrintable
  (-pr-str [o]))

(defprotocol IAtom)

(defprotocol IReset
  (-reset!  [o new-value]))

(defprotocol IDeref
  (-deref  [o]))

(defprotocol IMeta
  (-meta [o]))

(defprotocol IWithMeta
  (-with-meta [o meta]))

(defprotocol ISwap
  (-swap!  [o f]  [o f a]  [o f a b]  [o f a b xs]))

(defprotocol IEquiv
  (-equiv [x other]))

(defprotocol IHash
  (-hash [o]))

(defprotocol IWriter
  (-write [writer s])
  (-flush [writer]))

(defprotocol IPrintWithWriter
  ; "The old IPrintable protocol's implementation consisted of building a giant
  ;  list of strings to concatenate.  This involved lots of concat calls,
  ;  intermediate vectors, and lazy-seqs, and was very slow in some older JS
  ;  engines.  IPrintWithWriter implements printing via the IWriter protocol, so it
  ;  be implemented efficiently in terms of e.g. a StringBuffer append."
  (-pr-writer [o writer opts]))

(defprotocol IWatchable
  (-notify-watches  [o oldval newval])
  (-add-watch  [o key f])
  (-remove-watch  [o key]))

;; Internal - do not use
(defn- hamt-make []
  (hamt/make {$ "hash" hash "keyEq" =}))

(defn array
  []
  (.. js/Array -prototype -slice (call arguments)))

(defn alength
  "Returns the length of the array. Works on arrays of all types."
  [array]
  (.-length array))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn to-array
  "Naive impl of to-array as a start."
  [s]
  (let [ary [$]]
    (loop [s s]
      (if (seq s)
        (do (.push ary (first s))
            (recur (next s)))
        ary))))

(defn into-array
  ([aseq]
   (into-array nil aseq))
  ([type aseq]
   (reduce (fn [a x] (.push a x) a) (array) aseq)))

;; Why is this here?

(defn assoc
  "assoc[iate]. When applied to a map, returns a new map of the
  same (hashed/sorted) type, that contains the mapping of key(s) to
  val(s). When applied to a vector, returns a new vector that
  contains val at index."
  ([coll k v]
   (if (nil? coll)
     (hash-map k v)
     (-assoc coll k v)))
  ([coll k v & kvs]
   (let [ret (assoc coll k v)]
     (if kvs
       (recur ret (first kvs) (second kvs) (nnext kvs))
       ret))))

(defn dissoc
  "dissoc[iate]. Returns a new map of the same (hashed/sorted) type,
  that does not contain a mapping for key(s)."
  ([coll] coll)
  ([coll k]
    (when-not (nil? coll)
      (-dissoc coll k)))
  ([coll k & ks]
    (if (not (nil? coll))
      (let [ret (dissoc coll k)]
        (if ks
          (let [args (into-array ks)]
            (.unshift args ret)
            (.apply dissoc nil args))
          ret)))))

(defn peek
  "For a list or queue, same as first, for a vector, same as, but much
  more efficient than, last. If the collection is empty, returns nil."
  [coll]
  (when-not (nil? coll)
    (-peek coll)))

(defn pop
  "For a list or queue, returns a new list/queue without the first
  item, for a vector, returns a new vector without the last item.
  Note - not the same as next/butlast."<commit_msg>Add meta getter, even though it'll never return anything but nil so far.<commit_after>(ns cljs.core
  (:require js/hamt))

;; Core protocols

(defprotocol IEncodeJS
  (-clj->js  [x])
  (-key->js  [x]))

(defprotocol IFn
  (-invoke
    ;; Yay Christmas tree!
    [_]
    [_ a]
    [_ a b]
    [_ a b c]
    [_ a b c d]
    [_ a b c d e]
    [_ a b c d e f]
    [_ a b c d e f g]
    [_ a b c d e f g h]
    [_ a b c d e f g h i]
    [_ a b c d e f g h i j]
    [_ a b c d e f g h i j k]
    [_ a b c d e f g h i j k l]
    [_ a b c d e f g h i j k l m]
    [_ a b c d e f g h i j k l m n]
    [_ a b c d e f g h i j k l m n o]
    [_ a b c d e f g h i j k l m n o p]
    [_ a b c d e f g h i j k l m n o p q]
    [_ a b c d e f g h i j k l m n o p q r]
    [_ a b c d e f g h i j k l m n o p q r s]
    [_ a b c d e f g h i j k l m n o p q r s t]
    [_ a b c d e f g h i j k l m n o p q r s t rest]))

(defprotocol ICollection
  (-conj  [rng o]))

(defprotocol IIndexed
  (-nth [coll n] [coll n not-found]))

(defprotocol ISeqable
  (-seq [o]))

(defprotocol ISequential)

(defprotocol IList)

(defprotocol IReversible
  (-rseq  [coll]))

(defprotocol ISorted
  (-sorted-seq  [coll ascending?])
  (-sorted-seq-from  [coll k ascending?])
  (-entry-key  [coll entry])
  (-comparator  [coll]))

(defprotocol IVector
  (-assoc-n [coll n val]))

(defprotocol IAssociative
  (-contains-key? [coll k])
  (-assoc [coll k v]))

(defprotocol IMap
  (-dissoc [coll k]))

(defprotocol ICounted
  (-count [coll]))

(defprotocol ASeq)

(defprotocol ISeq
    (-first [coll])
    (-rest  [coll]))

(defprotocol INext
  (-next [coll]))

(defprotocol ILookup
  (-lookup [o k] [o k not-found]))

(defprotocol ISet
  (-disjoin [coll v]))

(defprotocol IStack
  (-peek [coll])
  (-pop [coll]))

(defprotocol IReduce
  (-reduce [coll f] [coll f start]))

(defprotocol IPrintable
  (-pr-str [o]))

(defprotocol IAtom)

(defprotocol IReset
  (-reset!  [o new-value]))

(defprotocol IDeref
  (-deref  [o]))

(defprotocol IMeta
  (-meta [o]))

(defprotocol IWithMeta
  (-with-meta [o meta]))

(defprotocol ISwap
  (-swap!  [o f]  [o f a]  [o f a b]  [o f a b xs]))

(defprotocol IEquiv
  (-equiv [x other]))

(defprotocol IHash
  (-hash [o]))

(defprotocol IWriter
  (-write [writer s])
  (-flush [writer]))

(defprotocol IPrintWithWriter
  ; "The old IPrintable protocol's implementation consisted of building a giant
  ;  list of strings to concatenate.  This involved lots of concat calls,
  ;  intermediate vectors, and lazy-seqs, and was very slow in some older JS
  ;  engines.  IPrintWithWriter implements printing via the IWriter protocol, so it
  ;  be implemented efficiently in terms of e.g. a StringBuffer append."
  (-pr-writer [o writer opts]))

(defprotocol IWatchable
  (-notify-watches  [o oldval newval])
  (-add-watch  [o key f])
  (-remove-watch  [o key]))

;; Internal - do not use
(defn- hamt-make []
  (hamt/make {$ "hash" hash "keyEq" =}))

(defn array
  []
  (.. js/Array -prototype -slice (call arguments)))

(defn alength
  "Returns the length of the array. Works on arrays of all types."
  [array]
  (.-length array))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn to-array
  "Naive impl of to-array as a start."
  [s]
  (let [ary [$]]
    (loop [s s]
      (if (seq s)
        (do (.push ary (first s))
            (recur (next s)))
        ary))))

(defn into-array
  ([aseq]
   (into-array nil aseq))
  ([type aseq]
   (reduce (fn [a x] (.push a x) a) (array) aseq)))

;; Why is this here?

(defn assoc
  "assoc[iate]. When applied to a map, returns a new map of the
  same (hashed/sorted) type, that contains the mapping of key(s) to
  val(s). When applied to a vector, returns a new vector that
  contains val at index."
  ([coll k v]
   (if (nil? coll)
     (hash-map k v)
     (-assoc coll k v)))
  ([coll k v & kvs]
   (let [ret (assoc coll k v)]
     (if kvs
       (recur ret (first kvs) (second kvs) (nnext kvs))
       ret))))

(defn dissoc
  "dissoc[iate]. Returns a new map of the same (hashed/sorted) type,
  that does not contain a mapping for key(s)."
  ([coll] coll)
  ([coll k]
    (when-not (nil? coll)
      (-dissoc coll k)))
  ([coll k & ks]
    (if (not (nil? coll))
      (let [ret (dissoc coll k)]
        (if ks
          (let [args (into-array ks)]
            (.unshift args ret)
            (.apply dissoc nil args))
          ret)))))

(defn meta
  "Returns the metadata of obj, returns nil if there is no metadata."
  [o]
  (when (and (not (nil? o))
             (satisfies? IMeta o))
    (-meta o)))

(defn peek
  "For a list or queue, same as first, for a vector, same as, but much
  more efficient than, last. If the collection is empty, returns nil."
  [coll]
  (when-not (nil? coll)
    (-peek coll)))

(defn pop
  "For a list or queue, returns a new list/queue without the first
  item, for a vector, returns a new vector without the last item.
  Note - not the same as next/butlast."
{'fraction_non_alphanumeric': 0.1396462018730489, 'fraction_numerical': 0.0, 'mean_word_length': 2.426381461675579, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4094279', 'n_tokens_mistral': 3737, 'n_tokens_neox': 3625, 'n_words': 1552}