clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
mokr 2020-12-16T09:23:57.336900Z

Hi, does anyone know of a Clojurescript (graph) library that would allow me to throw a lot of node and link descriptions at it and then answer questions like: “How many separate (disconnected) graphs did you end up with?” And related: “What are the start nodes?“. My use case have directed links/edges, btw. I currently have a working solution that generate the input I need for a force directed visualisation in D3.js, but I believe it would open up new possibilities if I rewrote it to be powered by actual graph technology. I was hoping to use Ubergraph for this, but it does not support Clojurescript. Then I looked at Loom, but skimming the docs I’m not so sure it can answer those two questions.

p-himik 2020-12-16T09:40:26.337Z

For your first question, https://github.com/aysylu/loom has the connected-components function. For the second one, I'm not sure whether it has something but it should be easy to check manually by iterating over all nodes and checking that they only have outgoing edges. Of course, you will have to handle situations where there are many such notes (many "starts").

p-himik 2020-12-16T09:40:41.337300Z

Some other potentially useful libraries are mentioned here: https://github.com/simongray/clj-graph-resources

mokr 2020-12-16T09:43:13.337600Z

Thanks, @p-himik, this helps

mokr 2020-12-16T09:56:11.338200Z

I suspect I should look into something like adjacency matrices as well, but then I need to find something that allows me to use it without investing serious amounts of time to relearn everything I once knew about matrices. Right now I’m looking for low handing fruits…

Dennis Tel 2020-12-16T10:59:59.339500Z

hello 👋, I have a simple clojurescript that simply does a println of hello world. If I build using lein with advanced optimisations I get a file of around 95kb. Is this expected? I thought the google closure compiler would optimize it to the bare minimum?

Dennis Tel 2020-12-16T11:04:13.339800Z

Ah I was using println instead of js/console.log, which makes a drastic difference

Dennis Tel 2020-12-16T11:12:20.340Z

hmmm as soon as I unclude a (defn hello [] (js/console.log "hello")) definition its 95kb again…

p-himik 2020-12-16T11:17:21.340200Z

I just compiled

(ns clj-playground.single)

(defn hello [] (js/console.log "hello"))

(hello)
with shadow-cljs with these build arguments:
:compiler-options {:output-feature-set :es6}
:js-options       {:babel-preset-config {:modules "commonjs"
                                         :targets "chrome > 70"}}
It resulted in a 219 characters JS file.

Dennis Tel 2020-12-16T11:18:49.340800Z

ah maybe I should elaborate: I’m using Lein with cljsbuild. I’m trying to setup a project to create a library that can be used both from the JVM and from JavaScript.

(ns clojure-multi-test.core)

(defn hello []
  #?(:clj  (println "Hello from Clojure")
     :cljs (js/console.log "Hello from ClojureScript!")))

(hello)
:cljsbuild {:builds [{:source-paths ["src"]
                        :compiler    {:output-to     "resources/public/js/main.js"
                                      :optimizations :advanced
                                      :target :bundle
                                      :pretty-print  false}}]}

Dennis Tel 2020-12-16T11:19:25.341Z

Is clsjbuild still a viable solution or should I integrate shadow-cljs into lein?

p-himik 2020-12-16T11:19:49.341200Z

Interestingly, in my case hello was just inlined there. No idea about cljsbuild, sorry. I've been using shadow-cljs for years now, cannot complain at all.

p-himik 2020-12-16T11:20:04.341400Z

Let me try with the conditionals first though.

Dennis Tel 2020-12-16T11:21:03.341600Z

shadow-cljs does seem more advanced/appropriate but as a clojure n00b i’m still trying to figure out what a nice project/build setup would be for this

p-himik 2020-12-16T11:21:06.341800Z

Yep, still works just fine, still inlines hello.

Dennis Tel 2020-12-16T11:21:39.342Z

:thinking_face:

p-himik 2020-12-16T11:21:44.342200Z

FWIW, my perfect setup is shadow-cljs + clj CLI (i.e. tools.deps.alpha).

Dennis Tel 2020-12-16T11:21:57.342400Z

yeah I’ve heard about clj

Dennis Tel 2020-12-16T11:22:18.342600Z

might give that one a try. Probably can also build JARs with that 😄

p-himik 2020-12-16T11:22:55.342800Z

You might be interested in this project then: https://github.com/seancorfield/depstar

Dennis Tel 2020-12-16T11:24:04.343100Z

ehhh that seems pretty complex 😄

Dennis Tel 2020-12-16T11:24:44.343300Z

But i’ll have a more in depth look, thanks for the suggestion 🙂

p-himik 2020-12-16T11:24:54.343500Z

Leiningen approach (that I don't really like) - have everything under one roof, promote plugin creation, inadvertently assist creating a closed ecosystem. CLJ CLI approach (that I do like) - have a tool that can run anything, allow anything, explicitly promote an open ecosystem.

Dennis Tel 2020-12-16T11:25:09.343700Z

First i’ll try to get shadow-cljs setup using CLJ

p-himik 2020-12-16T11:25:37.343900Z

Make sure to at list skim through shadow-cljs documentation - it's really good and answers 99% of all questions, including the setup.

Dennis Tel 2020-12-16T11:26:32.344100Z

:thumbsup: kudos to you sir!

👍 1
Dennis Tel 2020-12-16T11:51:58.344400Z

Just one question though: How do I prevent the closure compiler to strip a namespace/function definitions if I want to make a library?

p-himik 2020-12-16T11:53:36.344600Z

If the library is to be used by CLJS, you don't need to do anything because you won't be shipping the compiled code. If it's to be used by JS, then just add ^:export metadata to the symbol: https://clojurescript.org/reference/advanced-compilation#access-from-javascript

Dennis Tel 2020-12-16T12:23:09.345Z

@p-himik awesome, got it working using shadow-cljs and have a 825 byte node-library now 😄 Next step is setting up a repl and a jvm build, thank you very much for getting me started 😄!

p-himik 2020-12-16T12:23:45.345200Z

Awesome! Good luck and have fun. :)

tvaughan 2020-12-16T12:43:18.348200Z

I'm trying to interop with svg-edit, and it has an api that looks like:

svgCanvas.setSvgString('string')(function (data, error) {
     if (error) {
     // There was an error
     } else {
     // Handle data
     }
});
I don't understand this syntax, specifically how the callback is being passed in. Is it possible to make use of this in clojurescript? What would that look like? Thanks

Renato Alencar 2020-12-16T12:59:32.348300Z

It would be probably something like this:

((.setSvgString svgCanvas "string") (fn [data error]
                                      (if error
                                        ;; handle error
                                        ;; handle data)))

➕ 1
tvaughan 2020-12-16T13:04:22.348700Z

Ah, ok. That makes sense. Thanks @renatoalencar.73

Renato Alencar 2020-12-16T13:10:30.348900Z

I'm glad to help