Error formatting macro: pagetree: java.lang.NullPointerException
Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

Rationale

The ClojureScript analyzer could be modified to analyze Clojure code. This could be provided as a library to be called a la carte.

Challenges

Analyzer doesn't understand macro definitions (defmacro's)

  • Solution: `require` namespace before analysis
    • assuming a macro is only defined once
    • compiler should pick up any uses of the macro before definition, so don't need to know where in the namespace macro is defined

Dynamic loading and aliasing

  • ClojureScript has no compiler at runtime, so all dependencies and aliases are known at compile time
  • Clojure has `refer`, `require`, `import`, `alias`
    • Can be called dynamically at runtime
      • Impossible to compute all dependencies at compile time
        • Seems like a losing battle
          • Could we analyze clojure.core? Uses dynamic `load`, `require`
          • clojure.main?
        • Could compromise, warn on unresolvable alias/require, then assume analyzer cannot be trusted
          • allows them to be scattered around the file (like clojure.core), 
            • should be good enough to analyze clojure.core
              • which seems like a reasonable goal
  • Implementation
    • assume namespace information is more volatile
eg. can't assume all forms in a `do` have the same environment. Could change aliases, refers, requires etc.
ClojureScript doesn't have this issue.

Instead of propagating the `(:ns env)` of the `do` to its children (as in CLJS), should lookup namespace information for each form (but propagate locals and any other `env` keys as normal)

Distinguishing context of forms

  • Two important contexts to differentiate
    • forms inside fn body
    • forms not inside fn body
  • important difference
    • if first reference to `mynum` on line 3 is treated as a "potential" var lookup, its value would be 2 instead of 1
  • Implementation
    • [:context :fn] or [:context :top] keys in env
    • or dynamic var
Labels: