Re: tools.analyzer help

2015-10-13 Thread Gregg Reynolds
On Mon, Oct 12, 2015 at 7:27 AM, benedek fazekas 
wrote:

> hi Gregg,
>
> I am not aware of any extensive documentation apart from the qiuckref and
> the readmes. However can point you to two projects using tools.analyzer
> extensively:
> https://github.com/jonase/eastwood
> and
> https://github.com/clojure-emacs/refactor-nrepl


Thanks.  I took a look and quickly realized it would be wiser to follow the
author's advice and fire up a repl and start experimenting with the AST.
And I've already made substantial progress!  Clojure is so wonderful.
Maybe a tutorial will come of it; something like swannodette's
excellent ClojureScript
Analysis and Compilation

would
be nice.

>
>
> this maybe a bit of help. re. AST and eval: as far as I know
> tools.analyzer also evals the code it builds AST for, although this might
> depend on which entry point you use on its API.
>

I did find this on the analyzer.jvm README:  "the analysis of a clojure
form might require the evaluation of a previous one to make sense."
 Apparently the world of Clojure analysis is not quite the same as the
world of classic parsing etc. (e.g. the Dragon Book
.)

Thanks,

Greggg

-- 
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.


Re: tools.analyzer help

2015-10-13 Thread Nicola Mometto
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  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
>
> 
>   {{item}}
> 
>
> 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.


tools.analyzer help

2015-10-12 Thread benedek fazekas
hi Gregg,

I am not aware of any extensive documentation apart from the qiuckref and the 
readmes. However can point you to two projects using tools.analyzer extensively:
https://github.com/jonase/eastwood
and
https://github.com/clojure-emacs/refactor-nrepl

this maybe a bit of help. re. AST and eval: as far as I know tools.analyzer 
also evals the code it builds AST for, although this might depend on which 
entry point you use on its API.

cheers,

-- 
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.


tools.analyzer help

2015-10-11 Thread Gregg Reynolds
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


  {{item}}


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.