Fork me on GitHub
#cljs-dev
<
2016-09-21
>
darwin08:09:50

CLJS-1507 related question, I wonder if there could be a macro which would collect all macro namespaces and macro method names and export them into generated cljs source as data. I need it for Dirac: https://github.com/binaryage/dirac/issues/39 A poor man’s solution would be something like http://clojure.github.io/tools.namespace/#clojure.tools.namespace.find/find-namespaces, and then read all the files and extract defmacro symbols, but that may not be reliable. It would be better to query cljs compiler’s clj environment for all loaded macros somehow.

dnolen12:09:26

@darwin cljs.analyzer.api has helpers to return ns information

darwin12:09:20

thanks, going to look into that

dnolen12:09:03

maps representing ns information contain macro information

darwin12:09:43

when I use cljs.analyzer.api from some macro expanded in some cljs file, will it see “full picture” or just current state, that means all the code loaded/processed up to this point

darwin12:09:20

I need holistic view and collect all macros from all namespaces and generate it into selected cljs as data

dnolen12:09:27

read the docstrings and try it 🙂

darwin12:09:57

sounds like a fun afternoon 🙂

dnolen12:09:10

note they all take a compiler environment

dnolen12:09:18

which means you need to construct that and pass that to build

dnolen12:09:27

otherwise one will be created internally which you can’t get at

dnolen12:09:50

taking a quick look build tools like Figwheel & cljs-build will be informative here

darwin12:09:19

ok, thanks, will study it and see how far I can get

dnolen12:09:48

also the analyzer and compiler tests will be informative how this stuff actually works

dnolen12:09:02

(in the ClojureScript repo)

dnolen15:09:51

I added a bunch of newbie friendly tasks today http://dev.clojure.org/jira/secure/IssueNavigator.jspa?mode=hide&amp;requestId=10616 almost all of them are trivial clojure.spec stuff

richiardiandrea16:09:09

@darwin I don't know if I understand correctly, but you can also check what replumb.ast does: https://github.com/Lambda-X/replumb/blob/master/src/cljs/replumb/ast.cljs

richiardiandrea16:09:48

If I do not understand correctly, apologies 😄

darwin16:09:13

thanks, yes, that is what I need, list of all public macros from all available namespaces

darwin16:09:45

but how do I construct that “env” to pass into your functions?

darwin16:09:07

sorry, haven’t studied analyzer and other related stuff yet

richiardiandrea16:09:39

in bootstrap you build it yourself, usually ..and you store it in an atom

richiardiandrea16:09:39

then you pass it to all the calls to eval or eval-str...

darwin16:09:56

I understand that in repl this gets built incrementally as user is executing commands in the repl, but I need this for user’s code when he includes my library

richiardiandrea16:09:40

well, I guess in a require right?

richiardiandrea16:09:37

ah no wait, so you are aiming at already compiled code

richiardiandrea16:09:46

that includes your lib

darwin16:09:58

yes, my cljs file gets required somewhere in his project (typically via :preloads) and I want to grab all his macros at that point and export it as data for dirac to use

darwin16:09:18

not compiled, my lib (dirac.runtime) will be compiled with his app

darwin16:09:22

he requires it

darwin16:09:35

maybe naive idea: he requires dirac.runtime.cljs, I call my macro there, which in turn discovers all .clj files and requires them, it updates compiler env this way and now I can start using that env to ask analyzer questions about macros

darwin16:09:00

I’m worried about that require part, that could cause a lot of troubles (requiring broken files on classpaths etc)

darwin16:09:06

and also performance issues

richiardiandrea16:09:18

ok yes so everything is at runtime on already compiled javascript...it looks like you need bootstrapped cljs

darwin16:09:54

I’m telling you, my runtime library will be included in his project during compilation

darwin16:09:30

and I have to stay away from bootstrapped, cannot force people to setup their project to be bootstrap-compatible just for dirac

darwin16:09:28

maybe an ok solution for me would be something like :postloads. having my namespace included “last"

richiardiandrea16:09:52

I am checking in the cljs source if I can find a place when you can start digging

darwin16:09:53

this way I would know that calling a macro at that point would be pretty ok, because env would contain all namespaces project used

richiardiandrea17:09:19

yeah I don't know if there is something like that, David/Mike know more for sure 😄

darwin17:09:55

by “included" I really meant “analyzed”

richiardiandrea17:09:15

yes that part was clear, you need a step in between

richiardiandrea17:09:28

kind of like a macro step

richiardiandrea17:09:36

but with your custom code

darwin17:09:03

another really hacky idea is to force people to setup another build step, which will run in the same JVM

darwin17:09:15

after the normal one

richiardiandrea17:09:26

here is the compiler env

darwin17:09:27

and I would “steal” compliler env from previous run

darwin17:09:42

that is definitely possible with cljsbuild

richiardiandrea17:09:29

yeah, you need to intercept that *compile* thing when it is still filled up with the analyzed data

darwin17:09:18

have to go, thanks for the suggestions

darwin17:09:32

I’m not sure if I’m going to pursue this

darwin17:09:01

macros work quite fine in Dirac right now, code completions are not that important for me burn more time on it

richiardiandrea17:09:11

not sure, but curious to know, thanks for sharing 😉

richiardiandrea17:09:34

and thanks for your cool work on Dirac I use it every day