Interface to Clojure's Analyzer
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 63 commits behind frenchy64:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

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


Current version: 0.1.2


  • work out how to analyze a leiningen project.clj file
  • analyze clojure.core
  • get rid of requirement to provide namespace
  • 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
  • should we clump all literals into :op :literal ?


General Usage

This library takes a form, and some environment information, then passes it to the Compiler's analysis phase.

We then recursively convert the Java objects returned by the Compiler into maps, with :op and :env keys. The actual keys that get converted are easy to check, just search the source at analyze.core, using the :op keys as reference.

This is kind of rich information the analyzer can derive from expressions.

(Integer. 2)

expands to:

{:op :new,
 :env {:locals {}, :ns {:name clojure.core}},
 {:name java.lang.Integer,
  :declaring-class java.lang.Integer,
  :parameter-types [int],
  :exception-types [],
  :flags #{:public}},
 :class java.lang.Integer,
 ({:op :literal,
   :env {:locals {}, :ns {:name clojure.core}},
   :val 2,
   :Expr-obj #<NumberExpr clojure.lang.Compiler$NumberExpr@17bf874>}),
 ({:op :literal,
   :env {:locals {}, :ns {:name clojure.core}},
   :val 2,
   :Expr-obj #<NumberExpr clojure.lang.Compiler$NumberExpr@17bf874>}),
 :Expr-obj #<NewExpr clojure.lang.Compiler$NewExpr@3dbe0>}

Check for incorrectly placed docstrings

(defn myfn [a]
  "This is a fn"
  (doseq [a [1 2 3]
    (+ a (inc a))))

Surely a beginner mistake, right?

Run the checker in analyze.examples.docstrings to find out. :)

Check for side-effects in transactions

  (set! *ns* 'myns))

Test the checkers by running analyze.examples.side-effects