Fork me on GitHub

Basically what you're saying is that InterceptorComponent describes a superset of IntoComponent behavior and thus anything that extends InterceptorComponent implicitly can implement IntoComponent. Trying to extend the one protocol onto the other lies madness, but you could write an adapter fn that returned a reifyed instance with implementations for both IntoComponent and InterceptorComponent. It would be indistinguishable from the input value (with regards to the InterceptorComponent protocol...) and could also participate in the IntoComponent protocol.


Alternatively, if you actually could implement IntoComponent with your new protocol, an implementation of IntoComponent can be expressed entirely in terms of the interface InterceptorComponent. Extension is just saving you having to write the IntoComponent implementations when you're defining your record/type, so why not macro your way out of that hole with e.g. definterceptorcomponent which expands to deftype with the IntoComponent protocol specs tacked onto the end of the user supplied body?

Alex Miller (Clojure team)03:05:17

it's intentional that protocols cannot be extended onto protocols. that said, protocols are nothing more than maps of functions and as such, there are ways to programatically get this effect. generally though, I've had better luck by extending a protocol to Object, then using conditional code to dynamically extend the concrete type you've received (which satisfies some secondary protocol) to the first protocol


are there tools to provide performance details (mainly time-to-run) of all functions called from a parent function at runtime? i have a main function that kicks off loads of queries, calculations etc. i could time each one, but given how nested this code is i was hoping for an automatic solution.

Ivar Refsdal10:05:00

I've used tufte ( ) and its defnp with good results


Hi I’m trying to write my own client for a telnet-like protocol, for a mud game. I need to parse a byte stream, and the type of messages are identified by some special bytes, you know, just like telnet.


Is there a lib that I can use to help parse the byte stream?


Thanks, but it doesn’t seem to be for parsing bytes?


it uses ByteBuffer, which has all the methods needed for pulling other types out of bytes


in fact, that's straightforward enough that I'd skip clojure libs / bindings and just feed the InputStream into a ByteBuffer via interop, and use that API


Is anyone using gerritjvv/clj-tcp? Somehow I’m getting error with it.


can I package all the dependencies in one uberjar, and my code in another jar. So I can deploy the dependencies only once(if no dependency changes).


Is it possible to use Cognitect's AWS library with Ring? I reported one dependency issue when using both libraries in #aws channel.


@kari.marttila looks like a dependency conflict with Jetty which you should be able to fix by specifying a compatible version directly in project.clj.


Simple question


how do I execute a full sql file with jdbc


just a bunch of CREATE TABLE IF NOT EXISTS calls


@emccue slurp it in, break it into statements (str/split on ;), and call db-do-commands on each one


@seancorfield, thanks. I'll check that tomorrow.


It worked. @seancorfield: thanks for your help!


like that?


Yeah something like that


When I'm at my computer I'll pull up the code we use at work to do the same thing


Execution error (SQLException) at org.sqlite.core.NativeDB/throwex (
The prepared statement has been finalized


You probably need to tell db-do-commands not to use a transaction


same error


Hard to debug when I'm on my phone 🙃 If you can post more details in #sql I can take a look when I'm at my computer later


I remember looking into migratus for something. But use a different separator and split on that. I thought I remember the underlying thing not liking terminating semi colons


I don't know if this is the issue, but clojure.string/split has some non-intuitive behavior with separators at the end. TLDR; use a negative limit parameter. See for some examples. I got bitten by this recently.


I think the end result was that the batched statements can’t have terminating semicolons (this was on Postgres not sure what your dB is)


The split ended up producing an empty SQL statement and that's what throws the exception.


(str/split contents #";\s*\n") or (str/split contents #";.*\n")


should I use *ns* to get the qualified symbol in macro? like (my-macro (+ 1 2)), I want + as clojure.core/+.

Björn Ebbinghaus21:05:29

You want to use syntax quoting in this case

`x => clojure.core/+
'+ => x


Thanks for the reply. but the code in (my-macro ...) will not use syntax quote.


is there a way to know the namespace of that symbol?


Can you explain more about what you're trying to do?


user=> (defmacro my-macro [x] (first x))
user=> (my-macro (+ 1 2 ))
#object[clojure.core$_PLUS_ 0x1f38957 "[email protected]"]
The symbol is clojure.core/+ here.


In case this helps:

user=> (defmacro my-macro [x] (.ns (resolve (first x))))
user=> (my-macro (+ 1 2 ))
#object[clojure.lang.Namespace 0x707b1a44 "clojure.core"]


looks great. I'm trying to write a macro that can be used in both ->> and ->.


(-> (call (/ 1 0))
    (then (inc))
    (then (/ 2)))
;; => #error {
;;  :cause "Divide by zero"
;;  :via
;;  [{:type java.lang.ArithmeticException
;;    :message "Divide by zero"
;;    :at [clojure.lang.Numbers divide "" 188]}]
;;  :trace ...}

(-> (call 1)
    (then (inc))
    (then (/ 3)))
;; => 2/3

(->> (call 1)
     (then (inc))
     (then (/ 3)))
;; => 3/2

(some-> {:a 1 :b 2}
        (then (:a))
        (then (/ 2)))
;; => 1/2

(some->> {:a 1 :b 2}
         (then (:a))
         (then (/ 2)))
;; => 2

(some-> {:a 1 :b 2}
        (then (:c))
        (then (/ 2)))
;; => nil

(some->> {:a 1 :b 2}
         (then (:c))
         (then (/ 2)))
;; => nil
This is what I have currently.