Fork me on GitHub

Can you use a thread macro to walk through then/then/catch chains?

Gleb Posobin01:02:16

Yes, I can. But I want to wait until the promise returns so that the function in which I am using promises would be synchronous, and can't figure out how to do that.


I/we had the same problem and went for a small library -


@UQ4RJ22EA you can't do that - you can't block the single js thread. async/await in js is syntactic sugar and is implemented with callbacks on promises


similar things can be done with macros in clojurescript, which is exactly what promesa does

Gleb Posobin00:02:34

I see, thank you! What's the practical way of working with promises then? Are js promises enough, or promesa has some advantages that warrant using it?


js promises are enough, but we use promesa to wrap the js interop and get a binding syntax which can be easier to program with than chaining. (we also use funcool/cats, to get the same async interface in clj and cljs, but that's a different story)


whichever way you do it though you have to structure your program as continuations - once you are in js promise-land there is no escaping it - you can't return a synchronous response to your caller

Gleb Posobin15:02:59

I see, thank you!


Hello, i’ve encountered a weird behavior: this forms throws an error:

(do (ns my.ns
      (:require [clojure.string :as s]))
    (s/split "a.b.c" "."))
but if i remove the do block it no longer throws. any idea? (please do not ask me why I want to do that 🙂 )


I think it’s just not allowed to do 🙂

simple_smile 4

how am I supposed to write a macro that emits ns forms ? (beside the the fact that I should not do it)


you can't write a macro that emits ns forms. the compiler does not support that.


can I hack something with (set! ...) that do the same thing ?


you didn't say what you are trying to do. so what would you set!?


I meant emitting (from a macro) a form semantically equivalent to the one that is in my original question: (but with set!)

(do (ns my.ns
      (:require [clojure.string :as s]))
    (s/split "a.b.c" "."))
Am I more clear this way ?


no. there is nothing in that example where set! would do anything


also you that that the macro would emit that. I'm not sure what the original form for this would be?


but chances are that whatever you are trying to do is not possible in CLJS. namespaces have a rather strict stucture and cannot be modified dynamically


ok I see, thank you a lot for your time and those informations ! and for shadow-cljs which is awesome 🙂


@thheller ok i see, the truth hurts... but thank you.


You can try to use in-ns

(defmacro my-ns [ns-sym ns-require-list & body]
     (in-ns ~ns-sym)
     (require (quote [email protected]))
     [email protected]))


this is ugly as hell ) bit it is working


it doesn't work in CLJS.


clojure is much more flexible in this regard


then sorry for the noise


@pbaille A way around these limitations could be code generation before invoking the compiler: just generate code and write to disk once


Yes I see, thank you for the idea. I’m working on a macro that let you define sub namespaces in a straightforward way, partly because i’m a bit annoyed of the coupling file/namespace in clojure(script), so generating those before compiling defeats the point sadly.


you can also use plain maps as pseudo-namespaces maybe


yes it could do the trick but it is not really what i’m aiming for, i’ve got the macro working well in clojure and now I want the same thing in clojurescript... 🙂 I’m wondering if I can hack something with (set! ...)


Maybe a bit late for this advice now, which you have learned the hard way and thus will always remember: If you want some namespace hackery to work in both Clojure and ClojureScript, do the ClojureScript version first 🙂

😉 4

depending on your problem of course


Hi guys, any ideas on how to use material-ui in a reagent project? Many thanks!


Thanks @lilactown will try it!