Fork me on GitHub
#clojure
<
2024-03-07
>
azimpel18:03:00

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)

hiredman18:03:58

((fn f [m node] {:node node :children (map f (get m node))}) ... "ROOT")

p-himik18:03:24

Wrong number of args.

hiredman19:03:13

written by but not run, etc, etc, etc

hiredman19:03:32

(you need to partial f with m)

jpmonettas20:03:40

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]]]]]]]]]]]

azimpel21:03:40

Thank you @U0NCTKEV8, @U0739PUFQ ! I was missing the graph as a parameter in my recursion :face_palm: Clojure is just so amazing and fun.

Takis_19:03:49

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.

p-himik20:03:15

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.

José Javier Blanco Rivero20:03:37

I'm afraid I can't help, but I'm curious: why is this a good idea?

Takis_21:03:09

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

Takis_21:03:44

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

Takis_21:03:19

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.

p-himik21:03:48

> sadly we dont have those in Clojure You mean "extensions, plugins, etc."? But those aren't a business of a language.

Takis_22:03:32

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.

Takis_23:03:06

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

Takis_00:03:13

I made the same in spring, in spring is working fine, quarkus only doesnt work : https://github.com/tkaryadis/spring-demo

p-himik09:03:49

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?

p-himik09:03:56

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.

Takis_13:03:07

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.

p-himik13:03:50

> 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?

Takis_20:03:12

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

Takis_20:03:35

i guess its configurable i only found this page : https://quarkus.io/guides/class-loading-reference