Fork me on GitHub
#sci
<
2023-09-27
>
Jakub Holý (HolyJak)21:09:27

Pls advice on rewriting a macro to sci 🙏 I am rewriting https://github.com/fulcrologic/fulcro/blob/main/src/main/com/fulcrologic/fulcro/react/hooks.cljc#L179-L188 (and use-effect) macro - what gives me trouble is that the original impl refers to itself, and to the other macro. How do I make such as recursive impl correctly? The simpler case:

1 (ns sci.configs.fulcro.react.hooks
2   (:require [com.fulcrologic.fulcro.react.hooks :as hooks]))
3 (defn ^:sci/macro use-lifecycle 
4   ([&form &env setup] `(use-lifecycle &form &env ~setup nil)) ; FIXME Is this correct self-ref for a sci macro?
5   ([&form &env setup teardown] ...  `(use-effect ...))
At line 4, when the macro invokes its other arity, should I have what I do, or (sci.configs.fulcro.react.hooks/use-lifecycle &form &env setup nil)` , or possibly (hooks/use-lifecycle setup nil)` ? This will expand in a calling namespace, to which this macro-like is exposed as com.fulcrologic.fulcro.react.hooks/use-lifecycle . So if it makes a simple replacement in that context, then it macroexpands that again in the same context, then perhaps the last one is correct?? 🙏

borkdude21:09:56

The expansion should return the same as in clojure. the form and env are always inserted by the compiler/interpreter

borkdude21:09:54

but note that when you expose it as com.fulcrologic.fulcro.react.hooks/*** you should return this explicitly in the expansion or via the alias

borkdude21:09:35

so probably

`(hooks/use-lifecycle ~setup nil)
is what you want

borkdude21:09:01

else SCI tries to evaluate (sci.configs.***) which isn't exposed