Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (81 sloc) 2.45 KB

Interface to Clojure's Analyzer

Clojure's analysis compilation phase holds rich information about Clojure forms, like type/reflection information.

analyze provides an interface to this phase, callable a la carte. The output is similar to ClojureScript's analyzer.


Pull requests accepted from registered Clojure contributers


analyze.core=> (ast [1])
{:op :constant, :env {:locals {}, :ns {:name analyze.core}}, :val [1]}

analyze.core=> (-> (ast (if true 1 2)) clojure.pprint/pprint)
{:op :if,
 :env {:line 5, :locals {}, :ns {:name analyze.core}},
 {:op :boolean,
  :env {:locals {}, :ns {:name analyze.core}},
  :val true},
 {:op :number, :env {:locals {}, :ns {:name analyze.core}}, :val 1},
 {:op :number, :env {:locals {}, :ns {:name analyze.core}}, :val 2}}

analyze.core=> (-> (ast (fn [x] (+ x 1))) clojure.pprint/pprint)
{:op :fn-expr,
 :env {:locals {}, :ns {:name analyze.core}},
 ({:op :fn-method,
   :env {:locals {}, :ns {:name analyze.core}},
   {:op :do,
    :env {:locals {}, :ns {:name analyze.core}},
    ({:op :static-method,
      {:line 6, :source "REPL", :locals {}, :ns {:name analyze.core}},
      :class clojure.lang.Numbers,
      :method-name "add",
      {:name add,
       :return-type java.lang.Number,
       :declaring-class clojure.lang.Numbers,
       :parameter-types [java.lang.Object long],
       :exception-types [],
       :flags #{:static :public}},
      ({:op :local-binding-expr,
        :env {:locals {}, :ns {:name analyze.core}},
        {:op :local-binding,
         :env {:locals {}, :ns {:name analyze.core}},
         :sym x,
         :tag nil,
         :init nil},
        :tag nil}
       {:op :number,
        :env {:locals {}, :ns {:name analyze.core}},
        :val 1}),
      :tag nil})},
   ({:op :local-binding,
     :env {:locals {}, :ns {:name analyze.core}},
     :sym x,
     :tag nil,
     :init nil}),
   :rest-param nil}),
 :variadic-method nil,
 :tag nil}


Current version: 0.1.5


  • analyze a leiningen project.clj file
  • analyze clojure.core
  • does each expression have a line number attached?
  • try evaling the Expr forms returned by the analyzer and see what happens
  • Review SOURCE var
  • use :locals if necessary


See analyze.examples.* namespaces.

Something went wrong with that request. Please try again.