@reefersleep The HoneySQL library is written as .cljc
files and has test runners for both .clj
and .cljs
https://github.com/seancorfield/honeysql
Exactly what I was looking for, right in my .m2
. Another reason to be happy about honeysql 🙂
Thanks Sean!
@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.
I see Sean also uses that in HoneySQL
I thought you might chime in 😊 thanks! Same as @seancorfield, it seems. And it worked out fine for me, too!
🙂
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?
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.
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))
ok, let me give that a try
that did the trick. thanks!
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
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
So thanks for clarifying that!
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?
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
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=>
(Clojure 1.10.1)
@j0ni for protocols you can use satisfies?
thank you @borkdude, for releasing me from this rabbit hole
@ben.sless thanks for the heads up. It's ok for my use case, in a :ret
for a fdef
- only gets called in test
Always paste the code you typed. instance?
should work
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.
anyone here played with Loom's continuations yet? Or any channels specific to it?
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