This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # beginners (106)
- # boot (124)
- # cider (11)
- # clojure (105)
- # clojure-poland (2)
- # clojure-russia (28)
- # clojurescript (89)
- # core-async (14)
- # cursive (10)
- # datomic (7)
- # emacs (12)
- # garden (5)
- # hoplon (345)
- # immutant (127)
- # mount (2)
- # off-topic (24)
- # om (24)
- # onyx (8)
- # parinfer (51)
- # proton (2)
- # slack-help (4)
- # spacemacs (1)
If I want to hand a JS object over to a macro that generates a
defn for each property in the JS object... how would best I do that?
The macro would be called like this from CLJS:
(defcomponents js/MyJSObject) and if
MyJSObject has the properties
bar it should define two CLJS functions,
(defn foo-component [...] ...) and
(defn bar-component [...] ...).
Well, I can do
'(let [components# (~'js->clj ~components)] ...) in the macro (where
' is the backtick) but after that?
I can even get the macro to generate
(do (clojure.core/defn Button-component  foo) (clojure.core/defn Card-component  foo) (clojure.core/defn Heading-component  foo) (clojure.core/defn Layout-component  foo) (clojure.core/defn Text-component  foo))) for me but then I'd still need to evaluate it somehow for the
defns to take effect.
Yeah, then I could just have the compiler generate JS from the generated form, I suppose?
I have no idea how the bootstrapped compiler works or in what form it is available. I know it exists because people talk about it, that's all 😉
Another idea: If there was a way to apply
js->clj before the data is passed to the macro then that might work too. My understanding of data readers is limited, could I do something like
(defcomponents #clj js/MyJSObject)?
Yeah. I've written macros before that generated CLJS code - but from CLJ symbols and expression lists, not from JS objects that are unknown at compile time.
@jannis: so if you can start Nashorn (from a macro!), start bootstrapped ClojureScript inside of it, then you can do anything :)
https://gist.github.com/Jannis/ede3a929833798d7f2b3 - this is my macro at this point
@jannis: Paul Graham has a cool essay talking about Lisp freely mixing things up. Bootstrapped ClojureScript leads to that ability.
@mfikes: I have to admit jsx-fun is over my head right now. I see nashorn evaluating JS but I'm not sure how that helps in this case.
@dmitrig01: right. You can have
intern in bootstrapped ClojureScript, fwiw https://github.com/mfikes/planck/blob/284572b4b3acf7f59cd3e99485a6b9d53d303fc1/planck-cljs/src/planck/core.cljs#L217
it's always an exercise to figure out how to solve a problem like this without a macro if possible
@jannis: right, using Nashorn from within a macro to run bootstrapped ClojureScript is definitely at the deep end of the pool :) but it sounds fun
I assume Nashorn can only evaluate JS? So something would have to compile the generated CLJS expressions to JS before Nashorn can process them?
@jannis: right. I bet you can use the compiler from within a macro. Lots of interesting things could be done. Definitely a bigger problem than the one you set out to solve
I've got Nashorn to eval "5" and return the value to CLJS. Now I just need to eval ClojureScript 😉
@jannis: it's probably very hacky, but I could see using macroexpansion in bootstrapped ClojureScript to generate your defn forms, etc. at that point you are cobbling together a compiler within s compiler. Hmm
@jannis: if you are just doing this as a one-off, to generate code, maybe you could use an existing bootstrapped ClojureScript environment to do it
I wouldn't say it's a one-off. I have a JS React component library and I want to generate a function for each of the components that takes props and children and returns the result of
(js/React.createElement <component> #js <props> <children>).
My assumption was that the best way to approach this was to define these functions in the client after it has required the library via
:foreign-libs. It exports a single JS object whose keys are component names and whose values are their implementations (`<component>` in the above snippet).
So I thought I'd take that library object and generate the
defns for its components on the fly.
I wonder... instead of receiving the JS object from CLJS, could I instead load the corresponding
.js file from classpath with Nashorn, evaluate it, get the library object and generate CLJS code from it? So that I can then just use
(defcomponents "my-library.js") in CLJS?
:message ReferenceError: "window" is not defined in <eval> at line number 19320 at line 11
Hi, suppose I have N objects and M operations (some of which are doing network I/O). I want to call the sequence of operations in order for each of the N objects but allowing parallelism (across the objects) where possible. There is one synch (fan-in) point in the pipeline let's say at operation M-1. What's the best/easiest way to do this in core.async?
@johanatan: cats or promesa's
alet will do this for you.... dunno about core.async based solutions
@johanatan: I wrote my own helper to get the equivalent of the
Promise.all() fn you find in js promise libs
@val_waeselynck: promise.all() would be only one aspect of the solution here though no? Core.async already has
into for that.
_ but what about all the other special characters??
kmandrup: those functions are available in the repl, and have doc strings, etc. in clojure
the idea is that by having that job done by a function, you can accurately do the same translation you expect the compiler to do (in both directions)
kmandrup: and as I expected, cljs uses the same function name (different implementation) https://crossclj.info/ns/receipt/1.0.1/cljs.compiler.html#_munge
@kmandrup: I’d take a look at how
cljs.test finds all of the test functions as described in the bottom of http://swannodette.github.io/2014/12/17/whats-in-a-var/ and modify the approach to look for
^:export metadata instead
munge is definitely involved. Planck imitates it to call fns: https://github.com/mfikes/planck/blob/3eff90a881cb4df0ee32813cc02f1f3c245bbb4b/planck/PLKClojureScriptEngine.m#L1131-L1136
munge and just call it. Not a bad idea.
oh, I thought you had an interesting reason I had not thought of and I might be about to learn something, heh
Howdy peoples, what would you say its the first boilerplate or tutorial you would recommend for someone starting with clojurescript
Anyone interested in starting a Visual Studio code extension for Clojure via https://github.com/clojure/tools.analyzer ??
Visual Studio code looks to me like an IDE/editor that hits the "sweet spot" and is easy to extend... 😉