This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-07
Channels
- # announcements (1)
- # architecture (9)
- # babashka (3)
- # calva (10)
- # clj-http (13)
- # clj-kondo (11)
- # clojure (23)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (112)
- # clojure-uk (4)
- # clojuredesign-podcast (8)
- # clojurescript (10)
- # core-async (5)
- # cursive (7)
- # data-science (15)
- # datascript (2)
- # datomic (29)
- # emacs (5)
- # events (1)
- # hugsql (1)
- # hyperfiddle (9)
- # midje (1)
- # missionary (3)
- # music (1)
- # off-topic (34)
- # polylith (1)
- # re-frame (16)
- # shadow-cljs (117)
- # squint (19)
- # yamlscript (1)
I'm trying to render a hierarchical tree menu from a given node graph.
{"L1-1" ["L2-1" "L2-2"]
"ROOT" ["L1-1" "L1-2"]
"L1-2" ["L2-3"]
"L2-3" ["L3-1"]}
How could this model be rendered, let's say as a nested HTML tree consisting of [:ol [:li [:ol [:li] ,,,]] [:li ,,,]]
?
I try to wrap my head around a possible solution, but currently I'm stuck.
How can this issue be approached? Multiple alternatives come to my mind:
- walking the tree structure in a depth first manner (using clojure.walk
or zippers
) and converting nodes by visiting them.
- using some recursive algorithm (but here I'm struggling with rendering of sibling nodes)
you can do a recursive function like this :
(defn render-node [graph node]
(let [childs (get graph node)]
[:div.node
[:div.node-label node]
(into [:ol]
(map (fn [c] [:li (render-node graph c)]))
childs)]))
then for your example you would get :
(render-node g "ROOT")
[:div.node
[:div.node-label "ROOT"]
[:ol
[:li
[:div.node
[:div.node-label "L1-1"]
[:ol
[:li [:div.node [:div.node-label "L2-1"] [:ol]]]
[:li [:div.node [:div.node-label "L2-2"] [:ol]]]]]]
[:li
[:div.node
[:div.node-label "L1-2"]
[:ol
[:li
[:div.node
[:div.node-label "L2-3"]
[:ol [:li [:div.node [:div.node-label "L3-1"] [:ol]]]]]]]]]]]
Thank you @U0NCTKEV8, @U0739PUFQ ! I was missing the graph as a parameter in my recursion :face_palm: Clojure is just so amazing and fun.
Does anyone uses Clojure with Quarkus? I tried with gradle+clojurephant+quarkus and it didn't work(runtime error, couldn't see my Clojure classes), gradle+clojurepahnt+vert.x i didn't had any problems.
I see that you've also posted an SO question that has more details: https://stackoverflow.com/questions/78124075/how-to-make-quarkus-find-my-clojure-classes
To exclude the obvious - did you compile your Clojure code? I assume that the joy.Interop
class is supposed to be generate by Clojure.
I'm afraid I can't help, but I'm curious: why is this a good idea?
yes i compiled it, i can see the classes in build/clojure, i used clojurephant for that, i think its related with quarkus classLoader, it does some things like optimizations etc, clojurephant worked fine with vert.x for example, Quarkus has something called Runtime Class Loader. the problem is that i am new to gradle+quarkus so i doupt that i will find solution
Jose i like reactive programming, and i am trying to use Java libraries and frameworks, and Clojure to make things simpler. I don't know what is best, but i follow Java in general and use Clojure where it make sense. But i use only functional and reactive Java libraries like vert.x, project-reactor, webflux etc
Java so popular, for example Quarkus is 1 million lines of code with countless extensions, plugins etc, sadly we dont have those in Clojure, maybe this would make Clojure popular also, like a better way to use the functional side of java.
> sadly we dont have those in Clojure You mean "extensions, plugins, etc."? But those aren't a business of a language.
i mean our community is way smaller compared to java, and this effects our libraries and tools/frameworks. So i try to use java popular tools, from clojure, but i like only the functional/reactive java libraries. Quarkus is based on vert.x/mutiny that is reactive, thats why i try it.
i made a simple reproducable example here : https://github.com/tkaryadis/code-with-quarkus ./gradlew quarkusDev and going to http://localhost:8080/hello will cause the error
I made the same in spring, in spring is working fine, quarkus only doesnt work : https://github.com/tkaryadis/spring-demo
I see that your Clojure classes are compiled into a separate folder. Are you sure that folder is a part of the run-time classpath? Can you double-check?
I don't know Gradle at all (BTW, you might get a very low response rate just because of Gradle), but it seems that the path that contains Clojure-compiled classes is mentioned, but only for the compileJava
task.
Either Quarkus or Gradle seem to be doing some dynamic classpath stuff because I can't properly inspect the process with jinfo
or jps
. All I see is that code-with-quarkus/build/code-with-quarkus-dev.jar
is the only item on the classpath, and its manifest has only jars.
One other thing - please don't use 8080 or any other common ports for MREs. It's very likely with such ports that whoever is trying to help you will have to stop some of their own services.
yes Quarkus is doing dynamic classpath things, its not Gradle, for perfomance etc, i opened an Issue in Quarkus github, reply was they are not interested in Clojure. Maybe its fixable i opened the issue to the Clojurephant github, maybe they can fix it. Maybe its simple thing to solve it. thank you for trying to help.
> Quarkus is doing dynamic classpath things But how? Is it configurable? Alternatively, can you not simply compile the Clojure code right into the directory where the Java stuff is compiled?
i gave up, i will use spring for now, because i dont know gradle internals or quarkus internals and i doupt i can fix it, maybe the clojure gradle plugin maintainers can help, else i will retry sometime in case its simple to fix it, thank you for trying to help me
i guess its configurable i only found this page : https://quarkus.io/guides/class-loading-reference