Fork me on GitHub
#clojurescript
<
2020-02-03
>
Kamuela00:02:17

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.

richiardiandrea05:02:03

I/we had the same problem and went for a small library - https://github.com/arichiardi/fonda

mccraigmccraig09:02:45

@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

mccraigmccraig09:02:17

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?

mccraigmccraig07:02:12

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)

mccraigmccraig07:02:17

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!

pbaille15:02:22

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 🙂 )

Roman Liutikov15:02:39

I think it’s just not allowed to do 🙂

simple_smile 4
pbaille15:02:17

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

thheller15:02:09

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

pbaille17:02:21

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

thheller17:02:25

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

pbaille17:02:41

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 ?

thheller17:02:36

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

thheller17:02:31

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

thheller17:02:58

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

pbaille18:02:13

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

pbaille16:02:07

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

delaguardo16:02:55

You can try to use in-ns

(defmacro my-ns [ns-sym ns-require-list & body]
  `(do
     (in-ns ~ns-sym)
     (require (quote ~@ns-require-list))
     ~@body))

delaguardo16:02:37

this is ugly as hell ) bit it is working

thheller16:02:08

it doesn't work in CLJS.

thheller16:02:39

clojure is much more flexible in this regard

delaguardo16:02:58

then sorry for the noise

borkdude17:02:24

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

pbaille17:02:00

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.

borkdude17:02:18

you can also use plain maps as pseudo-namespaces maybe

pbaille17:02:36

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! ...)

andy.fingerhut20:02:23

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
borkdude17:02:40

depending on your problem of course

Christos21:02:28

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

Christos22:02:17

Thanks @lilactown will try it!