This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-21
Channels
- # announcements (4)
- # beginners (47)
- # cider (7)
- # clj-kondo (9)
- # cljs-dev (16)
- # clojure (8)
- # clojure-dev (33)
- # clojure-europe (39)
- # clojure-germany (2)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-uk (6)
- # clojuredesign-podcast (8)
- # clojurescript (12)
- # cursive (9)
- # datomic (24)
- # docker (3)
- # fulcro (23)
- # hoplon (7)
- # hyperfiddle (2)
- # java (5)
- # jvm (3)
- # leiningen (9)
- # lsp (6)
- # off-topic (75)
- # pathom (17)
- # polylith (21)
- # reitit (1)
- # rewrite-clj (11)
- # scittle (2)
- # shadow-cljs (57)
- # uncomplicate (6)
- # yamlscript (27)
Hi all. I'm trying to create a macro that relies on another macro. However, that another macro uses a backquote to resolve symbols from CLJS namespaces, and therefore my client macro won't compile. Is there a solution for this?
Some code:
(ns project.web.util.svg-icons
(:require [hickory.core :as hickory]
[reagent-mui.util :refer [create-svg-icon]]))
(defmacro resource-as-hiccup [resource-name]
(-> ( resource-name) slurp hickory/parse-fragment first hickory/as-hiccup))
(defmacro make-svg-icon [icon-name resource-name]
(create-svg-icon
`(r/as-element ~(resource-as-hiccup (str "project/web/icons/" resource-name)))
icon-name))
create-svg-icon
can be found https://github.com/arttuka/reagent-material-ui/blob/4fc4b44891919d2b84160eb411d52227dd89e0a5/src/core/reagent_mui/util.clj#L31. It has a react/memo
call inside a backquote. I get the error: "No such namespace: react"I do that. But the macro doesn't even compile. react
is being resolved when compiling the make-svg-icon
macro. Of course it doesn't exist there, as that is a Clojure context.
looks to me like defmacro resource-as-hiccup
should be defn resource-as-hiccup
? as in just a function you call, or in case the CLJS code actually does use it as a macro someplace you turn it into a function that the macro then calls
(defn resource-as-hiccup* [resource-name]
(-> ( resource-name) slurp hickory/parse-fragment first hickory/as-hiccup))
(defmacro resource-as-hiccup [resource-name]
(resource-as-hiccup* resource-name))
(defmacro make-svg-icon [icon-name resource-name]
(create-svg-icon
`(r/as-element ~(resource-as-hiccup* (str "project/web/icons/" resource-name)))
icon-name))
beware the macro hell though. you are digging quite deep with that many macros, some of those likely should just be functions.
You're right. In this case I think I will need to call create-svg-icon
as if it where a function, so that it is not compiled in place at the Clojure level. But the problem is that that macro is in a library...
just saw that the quote was misplaced. should likely be something like
(defmacro make-svg-icon [icon-name resource-name]
`(create-svg-icon
(reagent.core/as-element ~(resource-as-hiccup* (str "project/web/icons/" resource-name)))
~icon-name))
Of course, that works! Thank you!
Macros are expanded recursively