Hi Gregg,
tools.analyzer (specifically tools.analyzer.jvm) doesn't do any
evaluation of the forms by default if you're using the `analyze`
function, however there's an `analyze+eval` function that will do that
if you need.

Note that t.a.jvm is a *clojure* analyzer that will only be able to
analyze *valid clojure code*. It will not (out-of-the-box) support
analysis of forms containing invalid clojure expressions such as ones
where unbounded symbols appear.

However there are a number of extension points which effectively allow
that, assuming some (possibly non trivial) configuration.

If this is what you need, I'd look at passes-opts for the validate
pass and at the node spec for :local/:binding nodes. Take a look at
what the :env value is for bound locals, a possible solution could be
passing in an initial env map with constructed locals.


On Sun, Oct 11, 2015 at 9:36 PM, Gregg Reynolds <d...@mobileink.com> wrote:
> I'm trying to figure out how to use tools.analyzer.jvm but not getting very
> far.  My web searches didn't turn up much.  Anybody know of tutorials or
> howtos?
>
> Specifically, I can get the basic examples at
> https://github.com/clojure/tools.analyzer.jvm#ast-quickref to work, but not
> this:
>
> (pp/pprint (ana.jvm/analyze '(for [item items] (identity item))))
>
> I get "Could not resolve var: list-items", which puzzles me, since I thought
> the analyzer was just supposed to build an ast, not evaluate code.
>
> Anyway, I tried
>
> (def items ["a" "b" "c"]) => #'user/items
> (for [item items] (identity item)) => ("a" "b" "c")
> (pp/pprint (ana.jvm/analyze '(for [item items] (identity item)))) => spew!
> an endless stream of ast output along the lines of:
>
> {:children [:bindings :body],
>  :bindings
>  [{:children [:init],
>    :return-tag clojure.lang.LazySeq,
>    :init
>    {:children [:local :methods],
>     :return-tag clojure.lang.LazySeq,
>    ... etc. ad infinitum ...
>
> Based on the API doc for analyze I think I need to pass an env map, but I
> have no idea what's supposed to go in it and only an educated guess about
> What It All Means.
>
> Background:  I'm experimenting with Polymer. I want to write a macro that
> analyzes its argument and possibly replaces some nodes, resulting in an ast
> that will emit Polymer stuff.  For example, for dom-repeat:
>
>   (for [item person-list] (h/li item))
>
> will be translated into something like
>
> <template is="dom-repeat" items="{{person-list}}">
>   <li>{{item}}</li>
> </template>
>
> Thanks,
>
> Gregg
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to