This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-03
Channels
- # aleph (1)
- # announcements (3)
- # aws (36)
- # babashka (35)
- # beginners (25)
- # cider (14)
- # clj-kondo (3)
- # clojure (154)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-serbia (1)
- # clojure-uk (133)
- # clojurescript (36)
- # cursive (15)
- # data-science (7)
- # datomic (16)
- # fulcro (34)
- # immutant (9)
- # jackdaw (5)
- # jobs (1)
- # leiningen (39)
- # off-topic (25)
- # pathom (42)
- # planck (13)
- # play-clj (1)
- # re-frame (18)
- # reagent (6)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (16)
- # shadow-cljs (67)
- # sql (22)
- # testing (1)
- # uncomplicate (2)
- # vim (21)
- # vscode (6)
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 - https://github.com/arichiardi/fonda
@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
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
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 🙂 )how am I supposed to write a macro that emits ns forms ? (beside the the fact that I should not do it)
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 ?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 🙂
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))
this is ugly as hell ) bit it is working
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.
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 🙂
Thanks @lilactown will try it!