Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 0.1
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (53 sloc) 1.813 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.


See []


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

Jump to Line
Something went wrong with that request. Please try again.