clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
seancorfield 2020-11-27T00:16:20.241300Z

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

reefersleep 2020-11-27T00:19:40.241500Z

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

reefersleep 2020-11-27T00:19:44.241700Z

Thanks Sean!

borkdude 2020-11-27T10:05:48.243500Z

@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.

borkdude 2020-11-27T10:07:11.245700Z

I see Sean also uses that in HoneySQL

🍻 2
reefersleep 2020-11-27T10:07:19.245900Z

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

dharrigan 2020-11-27T10:08:51.246400Z

🙂

Adriaan Callaerts 2020-11-27T10:23:06.249800Z

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 Callaerts 2020-11-27T10:25:39.249900Z

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.

2020-11-27T10:33:28.250100Z

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 Callaerts 2020-11-27T10:34:05.250300Z

ok, let me give that a try

Adriaan Callaerts 2020-11-27T11:09:35.250500Z

that did the trick. thanks!

2020-11-27T11:15:45.250700Z

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 Callaerts 2020-11-27T11:16:56.250900Z

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 Callaerts 2020-11-27T11:17:16.251100Z

So thanks for clarifying that!

j0ni 2020-11-27T11:27:39.254100Z

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?

j0ni 2020-11-27T11:29:13.255400Z

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

j0ni 2020-12-01T19:27:01.445200Z

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=>

j0ni 2020-12-01T19:28:13.445400Z

(Clojure 1.10.1)

borkdude 2020-11-27T11:33:10.255700Z

@j0ni for protocols you can use satisfies?

j0ni 2020-11-27T11:34:22.256500Z

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

👍 1
j0ni 2020-12-01T19:24:10.445Z

@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

ghadi 2020-11-27T17:29:18.258800Z

Always paste the code you typed. instance? should work

Ben Sless 2020-11-27T21:09:37.260400Z

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.

lilactown 2020-11-27T23:28:21.261200Z

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

lilactown 2020-11-28T15:24:51.273300Z

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