Fork me on GitHub
#clojure
<
2020-11-27
>
seancorfield00:11:20

@reefersleep The HoneySQL library is written as .cljc files and has test runners for both .clj and .cljs https://github.com/seancorfield/honeysql

reefersleep00:11:40

Exactly what I was looking for, right in my .m2. Another reason to be happy about honeysql 🙂

borkdude10:11:48

@reefersleep I also have several .cljc projects. - https://github.com/borkdude/sci - https://github.com/borkdude/edamame I generally use the cognitect-labs test runner for running JVM tests and cljs-test-runner by @olical for running CLJS tests in node.

reefersleep10:11:19

I thought you might chime in 😊 thanks! Same as @U04V70XH6, it seems. And it worked out fine for me, too!

borkdude10:11:11

I see Sean also uses that in HoneySQL

🍻 6
Adriaan Callaerts10:11:06

question: in an effort to do some meta-programming, I am building an abstraction which needs to get a function from a namespace, but the names of the namespace and function are dynamic. Eg, I turned what used to be #'ns-name/fn-name into (var (symbol dynamic-ns-name dynamic-fn-name)) which I thought would work, but doesn't. Can someone spot my mistake?

Adriaan Callaerts10:11:39

In this example, ns-name and fn-name would be hardcoded in various places but always follow a fixed pattern, so I'd derive the dynamic-ns/fn-name from some other input and then "import" the function based on that derived name.

delaguardo10:11:28

var will work only if symbol can be resolved. if namespace is not loaded yet it will break. Instead you could try to use requiring-resolve which will dynamically require corresponding namespace and resolve var (requiring-resolve (symbol dynamic-ns-name dynamic-fn-name))

Adriaan Callaerts10:11:05

ok, let me give that a try

Adriaan Callaerts11:11:35

that did the trick. thanks!

delaguardo11:11:45

cool) but I was wrong about the reason why var is not working. The var is not a function but instruction to compiler to resolve symbol and only symbol to var for example (var (symbol "clojure.core" "apply")) will throw ClassCastException trying to cast clojure.lang.PersistentList into clojure.lang.Symbol the only valid form for var is (var apply) where argument is a symbol

Adriaan Callaerts11:11:56

yes, that was the exception I got but the documentation on var didn't give me the context that it can't be used as a runtime function

Adriaan Callaerts11:11:16

So thanks for clarifying that!

mhcat11:11:39

happy friday y'all, I have a question about reify - I'm trying to use instance? to verify that the object returned by reify is an instance of the protocol it reifies. It seems like that's not possible, because, well, it isn't. Is there a predicate, or other means I can use to determine which protocols are implemented by this object?

mhcat11:11:13

looking at the reify doc-string, it will always implement clojure.lang.IObj but doesn't mention any other features of the type of the object returned

ghadi17:11:18

Always paste the code you typed. instance? should work

mhcat19:12:01

user=> (defprotocol MyProtocol (a-meth [this]))
MyProtocol
user=> (def impl (reify MyProtocol (a-meth [this] :a-result)))
#'user/impl
user=> (instance? MyProtocol impl)
Execution error (ClassCastException) at user/eval196 (REPL:1).
class clojure.lang.PersistentArrayMap cannot be cast to class java.lang.Class (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.lang.Class is in module java.base of loader 'bootstrap')
user=> (satisfies? MyProtocol impl)
true
user=> (a-meth impl)
:a-result
user=>

mhcat19:12:13

(Clojure 1.10.1)

borkdude11:11:10

@j0ni for protocols you can use satisfies?

mhcat11:11:22

thank you @borkdude, for releasing me from this rabbit hole

👍 3
Ben Sless21:11:37

Be aware that satisfies has terrible performance. A work around is adding a method to the protocol, IFoo, foo?, which returns true for your objects and by extending the protocol to Object and nil, false for everything else.

mhcat19:12:10

@UK0810AQ2 thanks for the heads up. It's ok for my use case, in a :ret for a fdef - only gets called in test

lilactown23:11:21

anyone here played with Loom's continuations yet? Or any channels specific to it?

Ben Sless04:11:37

Hey Will :) There's #teknql but he focused more on fibers usage You could also try #java I'll reply to you by email later today, tldr I probably got some stuff wrong. From what I saw it's common to have one ContinuationScope and not open a new one every time

lilactown15:11:51

hey Ben, no rush! 😄 yeah I was hoping to see what other people are building on it and what techniques are falling out. that makes sense to me