Fork me on GitHub

Hi. How can I call a js function whose name is a string. For example, given s = "foobar", I want to call the method “foobar” on some object. Note that, I only know the string s.


(let [f (.bind (gobj/get obj s) obj)]

👆 1

Good to know.


If you’re ok with pulling in an extra dependency, you can also use for things like this e.g.

(ocall+ obj s)


@U04V15CAJ fyi, I was working on this.


@UGC0NEP4Y this should be supported in nbb.


you can also use (js/Reflect.apply (gobj/get obj s) obj (into-array []))


Yes. gobj is there.


user=> (require '[goog.object :as gobj]) (let [obj #js {"dude" (fn [& args] :hello)}] (js/Reflect.apply (gobj/get obj "dude") obj (into-array [])))
user=> :hello 


I directly use (.apply fun args) dunno what’s the difference


That also works, if the function is unrelated to the object


But sometimes this matters...

👆 1

hi! how can I get the current repl-env at macroexpansion time? Looking at it is getting it from &env but when I try it, it doesn't contain :repl-env key. What I'm trying to do is to eval some forms at macroexpansion time.


What’s the way to achieve the functionality of intern in clojurescript?


CLJS doesn't have vars at runtime so its not supported. you can achieve more or less the same just manipulating JS objects though.


Something like this?

(set! *ns*.a 4)
Invalid for the above though.


namespaces and vars do not exist in any meaningful way after :advanced optimizations. *ns* does not exist either outside macro evaluation or the REPL.


whatever you are trying to do you are better off not doing it with namespaces and instead your own object system


What I want to do is to create a variable in the current namespace, like a dynamic version of (def foobar 42), or to say (intern ns ’foobar 42) exactly. Understand there is some difference in cljs on how ns and var works. Yet, is my case doable?


@U2FRKM4TW This is my original question.


> to create a variable in the current namespace For what?


Exactly speaking, not in the current namespace. For example, say I have a function util/func, inside the function, I’d like to create a var in whatever namespace that invokes the util/func. It might be foo/func invokes util/func, then util/func shall intern a var in foo.


Yeah, but for what?


I'm trying to get to the X in the XY problem.


I develop with repl. The above code is not for production, just to make repl dev easier. The use case is, when I evaluate foo/func, then I can get a var say *f that contains some result of the evaulation.


I'm 80% certain that's not possible. And I'm 95% certain that even if it is possible, doing that wouldn't be worth it as you'd end up relying on some undocumented internals that can easily change in the next minor CLJS version. If I were you, I'd stick some registry into the user namespace, use tap> when I need some value be put in that registry, and add a tap that puts tapped values into that registry. Then, whenever you need some value, you'd use user/stuff in your REPL, which would be available from anywhere, without any need to (require 'user).


And, just in case you haven't tried it yet, I'd definitely recommend trying that with Not only you can see all the values that you've ever tapped, you can also send them back to your REPL.


That’s the thing I am doing.


@jpmonettas it's very impractical to try to evaluate ClojureScript at macroexpansion time


yeah, the thing is that I'm porting flowstorm debugger ( to Clojurescript, and I'm researching a way of instrumenting entire namespaces. So it is basically for interesting loaded namespaces, for every ns-interns, get the source form, instrument it (for tracing its execution) and then evaluate the instrumented one to replace the original


maybe there is another way of accomplishing the same :thinking_face: , that is the way I'm doing it in Clojure


can anyone tell me what ^:once does? the context is an Om.Next app with (defui ^:once MyComponent ...)


It's just metadata - nothing special about it. Om.Next itself handles it here:

Andrew Carlile19:05:35

Greetings wizards and warlocks, I'm having a proverbial aneurysm trying to upgrade a legacy app to reagent-mui 5. I've gotten most of the kinks worked out (so far) but I can't get spacing to work. The app compiles without error and the page renders mostly fine, except the layout has been thrown all out of whack. I did update the logic for pulling the spacing fn out of the theme, but it doesn't appear to have any affect on layout. could you spare some thoughts on anything that might have changed? I'm following the example project at as closely as I can detect. I'm also running into a real blocker with figwheel: normally, 'lein fig' results in a repl connection; mine does not; fig hot-reloading is kaputt. If I update cljs to 1.11.54, compilation crashes with an error related to 'RhinoErrorReporter' which my firm does not use and about which I find painfully little on google. Where is this coming from and how might I fix it? finally, when trying to use, compilation breaks with an error related to npm deps in reagent-mui. curiously, my stack-trace points to an @ symbol in a docstring. How can I include the necessary deps in my project to get data-grid off the ground?


> with an error related It would be helpful to actually have those errors here.

Andrew Carlile20:05:24

here’s the Rhino-related error message as a result of tryingto upgrade to 1.11.54:

lein fig
Execution error (NoSuchMethodError) at<clinit> ($Builder.buildOrThrow()Lcom/google/common/collect/ImmutableMap;

Full report at:


What are your dependencies?

Andrew Carlile20:05:29

here’s the error I get when trying to use

lein fig
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "target/public/cljs/main.js"
	[Figwheel] Failed to compile build dev in 9.637 seconds.
[Figwheel:WARNING] Compile Exception   target/public/cljs/dev/reagent_mui/x/data_grid.cljs   line:2  column:12

  No such namespace: @mui/x-data-grid, could not locate _CIRCA_mui_SLASH_x_data_grid.cljs, _CIRCA_mui_SLASH_x_data_grid.cljc, or JavaScript source providing "@mui/x-data-grid" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file target/public/cljs/dev/reagent_mui/x/data_grid.cljs

  1  (ns
  2    "Imports @mui/x-data-grid as a Reagent component.
  3     Original documentation is at  ."
  4    (:require-macros [reagent-mui.util :refer [with-unchanged-js-props]])
  5    (:require [reagent-mui.util :refer [adapt-react-class]]
  6              ["@mui/x-data-grid" :as MuiDataGrid]))

Andrew Carlile20:05:39

here’s my dependencies:

:dependencies [[org.clojure/clojure "1.11.1"]

                 ; HTTP Server + Handling
                 [metosin/reitit "0.5.5" :exclusions [org.clojure/spec.alpha]]
                 [metosin/ring-http-response "0.9.1" :exclusions [ring/ring-core]]
                 [metosin/muuntaja "0.6.7"]
                 [ring/ring-jetty-adapter "1.8.1"]
                 [org.clojure/tools.reader "1.3.3"]
                 [hiccup "1.0.5"]

                 ; METRICS / MONITORING
                 [yleisradio/new-reliquary "1.1.0"]         ; API To NewRelic

                 [org.clojure/core.async "1.3.610"]

                 ; Configuration
here’s my :plugins
:plugins [[lein-environ "1.2.0" :hooks true]
            [s3-wagon-private "1.3.4"]
            [lein-parent "0.3.8"]
            [lein-npm "0.6.2"]
            [lein-cljsbuild "1.1.8"]]
here’s profiles >:cljs
:cljs    {:source-paths ["src/cljs"]
                       :dependencies [[org.clojure/clojurescript "1.11.4"]
                                      [arttuka/reagent-material-ui "5.6.2-1"]
                                       ;:exclusions [arttuka/reagent-material-ui-js]]
                                      [reagent "1.1.1"]
                                      [cljsjs/react "17.0.2-0"]
                                      [cljsjs/react-dom "17.0.2-0"]
                                      [re-frame "1.3.0-rc3"]
                                      [metosin/reitit-frontend "0.5.18"]
                                      [cljs-http "0.1.46"]
                                      [cljsjs/auth0-lock "11.16.2-0"]]}

Andrew Carlile20:05:20

and profiles > dev

:dev     [:cljs
                       {:dependencies   [[com.bhauman/figwheel-main "0.2.18" :exclusions [clj-time joda-time]]
                                         [com.bhauman/rebel-readline-cljs "0.1.4"]]
                        :resource-paths ["target"]
                        :clean-targets  ^{:protect false} ["target"]}]


Nothing really catches the eye there. But if you ask Lein for a full dependency tree, does anything depend on the Closure compiler apart from the CLJS dep itself?

Andrew Carlile20:05:46

this is the only time closure appears in the results of running lein deps :tree

[org.clojure/clojurescript "1.11.4"]
   [ "v20210808"]
   [org.clojure/google-closure-library "0.0-20211011-0726fdeb"]
     [org.clojure/google-closure-library-third-party "0.0-20211011-0726fdeb"]
 [org.clojure/core.async "1.3.610"]

Andrew Carlile20:05:57

so I’m gonna guess “no”?

Andrew Carlile20:05:54

I would want to add these deps to an exclusions vector, right? like this?

:dependencies [[org.clojure/clojurescript "1.11.54"
                                       :exclusions [ "v20210808"
                                                    org.clojure/google-closure-library "0.0-20211011-0726fdeb"
                                                    org.clojure/google-closure-library-third-party "0.0-20211011-0726fdeb"]]
                                      [arttuka/reagent-material-ui "5.6.2-1"]


No, you don't want to exclude them - they are needed. Weird that you get that error though, especially given that both of the conflicting classes are in the same jar. Sorry, can't help further here - I myself have stopped using Lein and all related stuff a long time ago. Regarding your second error though - seems like you should install @mui/x-data-grid via NPM.

Andrew Carlile20:05:43

thanks! that stepped us over the @mui/x-data-grid error, only so that one relating to @mui/styles appears… am I going to have to do this for every node package mui depends on? sounds antipatternish. not to mention it blows up:

npm install @mui/styles
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0 || ^18.0.0" from @mui/[email protected]
npm ERR!   node_modules/@mui/base
npm ERR!     @mui/base@"5.0.0-alpha.82" from @mui/[email protected]
npm ERR!     node_modules/@mui/material
npm ERR!       peer @mui/material@"^5.2.8" from @mui/[email protected]
npm ERR!       node_modules/@mui/x-data-grid
npm ERR!         @mui/x-data-grid@"^5.11.1" from the root project
npm ERR!   peer react@"^17.0.0 || ^18.0.0" from @mui/[email protected]
npm ERR!   node_modules/@mui/material
npm ERR!     peer @mui/material@"^5.2.8" from @mui/[email protected]
npm ERR!     node_modules/@mui/x-data-grid
npm ERR!       @mui/x-data-grid@"^5.11.1" from the root project
npm ERR!   7 more (@mui/private-theming, @mui/styled-engine, @mui/system, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! @mui/styles@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0" from @mui/[email protected]
npm ERR!   node_modules/@mui/styles
npm ERR!     @mui/styles@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.


> am I going to have to do this for every node package mui depends on? Only for the ones you're actually using. Somewhere, you required - so, that's why you need that NPM package I mentioned. Same with @mui/styles. Why it blows up, though... well, the package itself is kinda broken - its siblings require React either 17 or 18, you have 18 installed, but the styles package for some reason doesn't list 18 as an acceptable version. You could try downgrading your React to 17.

Sameer Thajudin22:05:47

Why have you stopped using lein? I assume you have a better alternative. If that is the case I would like to know.


I'm using deps.edn and shadow-cljs. Shadow-cljs is just a hassle-free build tool for CLJS, with some nice extras on top. And using deps.edn is much simpler conceptually, even though it might not always be easier to use it. But plenty has been written on deps.edn vs Lein - on this server and in numerous blogs.