ClojureとClojureScriptで使える関数・マクロの違い

ClojureScriptではformat関数がないのか～と知って
ClojureとClojureScriptで使える関数・マクロの違いが気になって調べてみました。
ClojureScriptの方は、正式な手段がわからなかったのでソースを持ってきて解析しました。

cljs/cljs/core.cljsのコードからはソース中のdef～(privateでないもの)を取ってきます。
それだけだとマクロが入ってないのでclj/cljs/core.cljを持ってきて`(ns-publics 'cljs.core)`との差分を取ってマクロを追加しています。
※ClojureScriptの方はあまり正確ではないかも・・・

```core.clj
(ns cljs-sample.core
  (:require [clojure.string :as s]
            [clojure.data :as d]))

(def cljs-forms 
  (let [s (str "[\n" (slurp "src/cljs/cljs/core.cljs") "\n]")]
    (read-string (s/replace s "#js" ""))))

(def cljs-macros 
  (let [s (str "[\n" (slurp "src/clj/cljs/core.clj") "\n]")]
    (read-string (s/replace s "::ana/numeric" ""))))

(def defs (set '[def definline definterface defmacro defmethod defmulti defn defonce defprotocol defrecord defstruct deftype]))

(def clj-publics (set (keys (ns-publics 'clojure.core))))
(def cljs-publics 
  (let [f (fn [d x] (->> (filter #(d (first %)) x)
                         (map second)
                         (remove #(:private (meta %)))))
        m (d/diff (set (f #{'def 'defn} cljs-macros)) (set (keys (ns-publics 'cljs.core))))]
    (set (concat (f defs cljs-forms) (second m)))))

(def diff (d/diff clj-publics cljs-publics))

```

#### Clojureでのみ使えるもの

```:(sort_(first_diff))
(*' *agent* *allow-unresolved-vars* *assert* *clojure-version* *command-line-args* *compile-files* *compile-path* *compiler-options* *data-readers* *default-data-reader-fn* *e *err* *file* *fn-loader* *in* *math-context* *ns* *out* *read-eval* *source-path* *unchecked-math* *use-context-classloader* *verbose-defrecords* *warn-on-reflection* +' -' ->ArrayChunk ->Vec ->VecNode ->VecSeq -cache-protocol-fn -reset-methods EMPTY-NODE accessor add-classpath agent agent-error agent-errors alias all-ns alter alter-var-root aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short await await-for await1 bases bean bigdec bigint biginteger boolean-array bound-fn bound-fn* bound? byte-array cast char-array char-escape-string char-name-string char? class class? clear-agent-errors clojure-version commute compile construct-proxy create-ns create-struct dec' decimal? default-data-readers definline definterface defmacro defstruct deliver denominator destructure dosync ensure enumeration-seq error-handler error-mode eval extend extenders extends? file-seq find-keyword find-ns find-protocol-impl find-protocol-method find-var float-array float? format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface get-proxy-class get-thread-bindings import in-ns inc' init-proxy intern io! iterator-seq line-seq load load-file load-reader load-string loaded-libs locking macroexpand macroexpand-1 method-sig munge namespace-munge ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap num numerator pcalls pmap pop-thread-bindings primitives-classnames print-ctor print-dup print-method print-simple printf promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues ratio? rational? rationalize re-groups re-matcher read read-line read-string record? ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends remove-ns require resolve restart-agent resultset-seq send send-off send-via seque set-agent-send-executor! set-agent-send-off-executor! set-error-handler! set-error-mode! short-array shutdown-agents slurp spit struct struct-map supers sync the-ns thread-bound? unquote unquote-splicing update-proxy use var-get var-set var? vector-of with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-open with-precision with-redefs-fn xml-seq)
```


#### ClojureScriptでのみ使えるもの

```:(sort_(second_diff))
(*clojurescript-version* *main-cli-fn* *print-fn* *print-newline* *unchecked-if* ASeq ArrayChunk ArrayIter ArrayList ArrayNode ArrayNodeSeq Atom BitmapIndexedNode BlackNode Box ChunkBuffer ChunkedCons ChunkedSeq Cons Delay ES6EntriesIterator ES6Iterator ES6IteratorSeq ES6SetEntriesIterator Eduction EmptyList ExceptionInfo Fn HashCollisionNode IAssociative IAtom IChunk IChunkedNext IChunkedSeq ICloneable ICollection IComparable ICounted IDeref IDerefWithTimeout IEditableCollection IEmptyableCollection IEncodeClojure IEncodeJS IEquiv IFn IHash IIndexed IIterable IKVReduce IList ILookup IMap IMapEntry IMeta IMultiFn INIT INamed INext IPending IPrintWithWriter IRecord IReduce IReset IReversible ISeq ISeqable ISequential ISet ISorted IStack ISwap ITransientAssociative ITransientCollection ITransientMap ITransientSet ITransientVector IVector IVolatile IWatchable IWithMeta IWriter IndexedSeq IndexedSeqIterator KeySeq Keyword LazySeq LazyTransformer List MetaFn MultiFn MultiStepper NeverEquiv NodeSeq ObjMap PersistentArrayMap PersistentArrayMapIterator PersistentArrayMapSeq PersistentHashMap PersistentHashSet PersistentQueue PersistentQueueSeq PersistentTreeMap PersistentTreeMapSeq PersistentTreeSet PersistentVector RSeq Range RangeIterator RangedIterator RedNode Reduced START SeqIter Stepper StringBufferWriter StringIter Subvec Symbol TransientArrayMap TransientHashMap TransientHashSet TransientVector UUID ValSeq Var VectorNode Volatile add-to-string-hash-cache array array-chunk array-iter array-list array-seq array? bit-count bit-shift-right-zero-fill bitpos caching-hash cat chunked-seq clj->js clone cloneable? coercive-= coercive-boolean coercive-not coercive-not= completing dedupe divide eduction enable-console-print! ensure-reduced es6-entries-iterator es6-iterable es6-iterator es6-iterator-seq es6-set-entries-iterator ex-cause ex-message exists? extend-prefix fixture1 fixture2 gen-apply-to gensym_counter hash-keyword hash-string hash-string* implements? import-macros indexed? int-rotate-left is_proto_ iter iterable? js->clj js-arguments js-delete js-in js-invoke js-keys js-mod js-obj js-str key->js key-test keyword-identical? lazy-transformer m3-C1 m3-C2 m3-fmix m3-hash-int m3-hash-unencoded-chars m3-mix-H1 m3-mix-K1 m3-seed mask missing-protocol mk-bound-fn multi-stepper native-satisfies? nil-iter not-native obj-map object? persistent-array-map-seq pr-seq-writer pr-sequential-writer pr-str* pr-str-with-opts prim-seq print-map prn-str-with-opts random-sample ranged-iterator reduceable? regexp? run! seq-iter seqable? set-from-indexed-seq set-print-fn! simple-benchmark specify specify! spread stepper string-hash-cache string-hash-cache-count string-iter string-print this-as transduce truth_ type->str undefined? unreduced unsafe-bit-and update volatile! volatile? vreset! write-all)
```

#### 共通して使えるもの

```:(sort_(nth_diff_2))
(* *1 *2 *3 *flush-on-newline* *print-dup* *print-length* *print-level* *print-meta* *print-readably* + - -> ->> .. / < <= = == > >= aclone add-watch aget alength alter-meta! amap ancestors and apply areduce array-map as-> aset assert assoc assoc! assoc-in associative? atom binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean booleans butlast byte bytes case char chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? coll? comment comp comparator compare compare-and-set! complement concat cond cond-> cond->> condp conj conj! cons constantly contains? count counted? cycle dec declare defmethod defmulti defn defn- defonce defprotocol defrecord deftype delay delay? deref derive descendants disj disj! dissoc dissoc! distinct distinct? doall dorun doseq dotimes doto double double-array doubles drop drop-last drop-while empty empty? even? every-pred every? ex-data ex-info extend-protocol extend-type false? ffirst filter filterv find first flatten float floats flush fn fn? fnext fnil for force frequencies gensym get get-in get-method get-validator group-by hash hash-combine hash-map hash-ordered-coll hash-set hash-unordered-coll identical? identity if-let if-not if-some ifn? inc instance? int int-array integer? interleave interpose into into-array ints isa? iterate juxt keep keep-indexed key keys keyword keyword? last lazy-cat lazy-seq let letfn list list* list? long long-array longs loop make-array make-hierarchy map map-indexed map? mapcat mapv max max-key memfn memoize merge merge-with meta methods min min-key mix-collection-hash mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= nth nthnext nthrest number? object-array odd? or parents partial partition partition-all partition-by peek persistent! pop pop! pos? pr pr-str prefer-method prefers print print-str println println-str prn prn-str quot rand rand-int rand-nth range re-find re-matches re-pattern re-seq realized? reduce reduce-kv reduced reduced? reductions reify rem remove remove-all-methods remove-method remove-watch repeat repeatedly replace replicate reset! reset-meta! rest reverse reversible? rseq rsubseq satisfies? second select-keys seq seq? sequence sequential? set set-validator! set? short shorts shuffle some some-> some->> some-fn some? sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-symbol? split-at split-with str string? subs subseq subvec swap! symbol symbol? take take-last take-nth take-while test time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-add-int unchecked-byte unchecked-char unchecked-dec unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float unchecked-inc unchecked-inc-int unchecked-int unchecked-long unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int unchecked-remainder-int unchecked-short unchecked-subtract unchecked-subtract-int underive unsigned-bit-shift-right update-in val vals vary-meta vec vector vector? when when-first when-let when-not when-some while with-meta with-out-str with-redefs zero? zipmap)
```