Fork me on GitHub
#clojure-dev
<
2017-01-20
>
Alex Miller (Clojure team)21:01:03

@bronsa I’m working with some tools.analyzer.jvm stuff and I wanted to just check that my understanding is correct. What I would ideally like is that analyze+eval of an (ns foo) form would result in some observable change to the (new) current namespace. So my question is just verifying that there is nothing to do that “automatically” right now, right?

Alex Miller (Clojure team)21:01:35

it seems like the expanded ns form contains the call to (in-ns ) with a resulting :env and the new :ns in it which I could find and apply to the next call in its env :ns

Alex Miller (Clojure team)21:01:12

the greater context is in analyzing a .clj file without a priori knowing its namespace. I might just change that aspect instead, just trying to decide.

Alex Miller (Clojure team)21:01:53

oh, and a 2nd question I haven’t tried to answer myself is whether its possible to control gensym creation in analyzer macro expansion so its repeatable

bronsa21:01:45

@alexmiller so in *ns* = 'user, you'd like (analyze+eval '(ns foo)) to "report" that the current namespace got changed?

bronsa21:01:39

there's no available built-in that does that, other than inspecting the :env ns of the value next to in-ns, or doing a backup of the current *ns* pre analyze+eval and manually checking for change

Alex Miller (Clojure team)21:01:06

ok, I didn’t look at *ns* but that would work

Alex Miller (Clojure team)21:01:31

I can also see the change in the :namespaces of the global env, but that’s a little indirect

bronsa21:01:03

re: 2nd question I think with-redefs of gensym before analyze+eval is the only way to do it

Alex Miller (Clojure team)21:01:35

cool, I will give that a shot at some point

Alex Miller (Clojure team)21:01:49

thank you for the quick read

bronsa21:01:51

if you mean for stuff like

(defmacro foo [] (let [x (gensym)] `'~x)

Alex Miller (Clojure team)21:01:52

what I’d like is to get something repeatable if I grab the form for an analyzed expression

bronsa21:01:53

btw if you're running analyze+ns on a full file, consider using analyze-ns or look at its code and adapt it, there are a few gotchas that needs to be handled correctly

Alex Miller (Clojure team)21:01:23

I’m actually trying to avoid analyze-ns as I need more reader control

Alex Miller (Clojure team)21:01:28

but I have been looking at the code

Alex Miller (Clojure team)21:01:50

and I am adapting parts of it

Alex Miller (Clojure team)21:01:35

thank you for its existence :)

bronsa21:01:41

you mean for the :name field then? the auto-gensym t.a.jvm does on locals?

bronsa21:01:00

if that's the case you can probably control it by monkey-patching bits of the uniquify pass

bronsa21:01:54

altho that should already be deterministic

Alex Miller (Clojure team)21:01:28

won’t locals-counter in there be dependent on what’s already been analyzed?

bronsa21:01:40

it's bound anew on every analyzed form

Alex Miller (Clojure team)21:01:15

I haven’t looked at this in a couple months, so apologies I don’t have it at top of mind. was just asking while bothering you on other things. I think I’ve got enough pointers to be dangerous for now.