Fork me on GitHub
#clojure
<
2019-05-11
>
Alex00:05:02

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.

Alex00:05:17

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

joshkh09:05:41

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 ( https://github.com/ptaoussanis/tufte ) and its defnp with good results

markx12:05:24

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.

markx12:05:51

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

markx14:05:32

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

noisesmith17:05:26

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

noisesmith17:05:00

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

markx16:05:17

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

tianshu16:05:55

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

kari17:05:00

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

seancorfield17:05:53

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

emccue17:05:03

Simple question

emccue17:05:12

how do I execute a full sql file with jdbc

emccue17:05:26

just a bunch of CREATE TABLE IF NOT EXISTS calls

seancorfield17:05:42

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

kari17:05:46

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

kari08:05:20

It worked. @seancorfield: thanks for your help!

emccue17:05:19

like that?

seancorfield17:05:29

Yeah something like that

seancorfield17:05:15

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

emccue17:05:33

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

seancorfield17:05:16

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

emccue17:05:02

same error

seancorfield17:05:03

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

dpsutton17:05:13

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

dorab17:05:16

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 https://clojuredocs.org/clojure.string/split for some examples. I got bitten by this recently.

dpsutton17:05:52

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)

seancorfield18:05:05

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

seancorfield18:05:21

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

tianshu21:05:08

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

tianshu21:05:20

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

tianshu21:05:35

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

seancorfield21:05:20

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

seancorfield21:05:08

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

seancorfield22:05:40

In case this helps:

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

tianshu22:05:27

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

tianshu22:05:17

(-> (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 "Numbers.java" 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.