This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-01
Channels
- # announcements (1)
- # aws (3)
- # beginners (150)
- # boot (12)
- # calva (7)
- # carry (3)
- # cider (1)
- # clara (51)
- # cljdoc (17)
- # cljs-dev (17)
- # cljsrn (1)
- # clojure (64)
- # clojure-austin (2)
- # clojure-india (1)
- # clojure-italy (10)
- # clojure-nl (4)
- # clojure-spec (42)
- # clojure-uk (63)
- # clojurescript (24)
- # core-async (23)
- # cursive (6)
- # datascript (7)
- # datomic (5)
- # figwheel-main (43)
- # fulcro (74)
- # hoplon (7)
- # kaocha (30)
- # leiningen (32)
- # mount (51)
- # nrepl (34)
- # off-topic (29)
- # re-frame (6)
- # reagent (10)
- # reitit (13)
- # shadow-cljs (66)
- # slack-help (3)
- # spacemacs (2)
- # specter (5)
- # sql (2)
- # tools-deps (51)
- # yada (13)
I have a multi-method and a corresponding defmethod that should kick when the method is passed an object like {:type :mock ...}
.
(defmulti transport (fn [config]
(println "dispatching transport: " config)
(:type config)))
(defmethod t/transport :mock
[{:keys [driver topics]}]
...
)
I'm pretty sure I'm passing it an object with the right :type
. And in the ns, there's a require
on the namespace that defines the mock defmethod.
This is a test ns. When I run it on it's own, it behaves as expected but when run as part of an entire suite, it behaves like the required defmethod hasn't been loaded yet. Any tips on how to track the problem down?Turns out there was a duplicate ns that was overriding the one I needed due to a prior copy-paste error.
well, no because defmulti acts like defonce in that case, but something like that would be my first guess
you can check the identity of t/transport at load time by putting something like (println t/transport) after the multimethod, and then (println t/transport) again when the tests actually run
@cddr One trick is to add (def transport nil)
immediately above the defmulti
-- and that will force the defmulti
to be reapplied when you reload the ns.
Hello, I am having trouble when I use hugsql to get a map.
I’d guess that’s not related to HugSQL itself. I think you require
somewhere coercing function that converts Date into JodaTime (This happen in JDBC layer).
thanks.
I just want the date. Who can tell me why? thanks.
Check out https://github.com/clj-time/clj-time to deal with date objects.
thanks.
clojure compile
not emit clojure.tools.reader.reader_types.Reader
.(my dep tree com.taoensso/carmine -> com.taoensso/encore -> org.clojure/tools.reader
)
Hi! I am just starting to learn clojure.java.jdbc and postgresql in Clojure language, and I am stuck that when I am trying to update my data inside database, it just throw an error which “org.postgresql.util.PSQLException This ResultSet is closed.” Below is my code for update
(sql/execute! db ["UPDATE public.\"user\" SET user_last_login = to_timestamp(?), user_token = ? WHERE user_email = ?" (str timestamp) token email])
I also try this
(sql/update! db "public.\"user\"" {:user_last_login (str "to_timestamp(" timestamp ")") :user_token token} ["user_email = ?" email])
and I don’t know what to do, please help, thank you.
Pardon my EnglishTurns out there was a duplicate ns that was overriding the one I needed due to a prior copy-paste error.
I am printing the following to my terminal:
(defn my-data
[]
'({:first "Dan" :last "Smith"}))
(println my-data)
When this is logged to the console, the double-quotes
are not preserved. Is there a way to have them preserved in the terminal? (A REPL would do this but lets assume, for the sake of argument, I can only println
to a terminal window)(println (pr-str (vector {:first "Dan" :last "Smith"}))
Thank you!
@ampersanda There's a #sql channel which is a lot quieter than this one -- easier to get SQL/JDBC answers there. I've pretty sure your second one won't work since you're passing a literal string as the value of :user_last_login
(but I'd expect a different error).
Okay, thank you for your reply :)
If you can share more of your code in #sql and more of the exception you are seeing, that might help us to help you.
Anyone who's using CLJ-HTTP who knows if it's possible to hand it a SSLContext somehow?
Seems like changing the builders setting seems to do the trick.aka setSSLSocketFactory
Using :http-builder-fns hmm..
im digging into ways to write an extensible library via multimethods/protocols. this is my first real foray into this area of clojure, and i’m having a conceptual issue. if i have a type Foo
implementing protocol ABC
, is there a way to extend-type Foo ABC
such that I can provide some custom protocol fn implementation, but not all implementations (where not providing an override implementation will fall back to the original type’s impl)?
(defprotocol Test1 (-to-handler [dsl]) (-to-handler-2 [dsl]))
(deftype DefaultHTTP [dsl]
Test1
(-to-handler [_] #{dsl})
(-to-handler-2 [dsl] [dsl]))
(deftype MyHTTP [dsl]
Test1
(-to-handler [_] (-to-handler (DefaultHTTP. dsl))) ;; <= can this be avoided?
(-to-handler-2 [_] '(dsl)))
You can hack something around extend to do that, since it deals with maps of fns. Values all the way down
no, that doesn't exist - this intentionally isn't inheritance in that way
> this intentionally isn’t inheritance can you point me in the right direction with respect to why this is a bad idea?
you can get these symantics by having multiple multimethods (one for each method) with :default implementations
@lwhorton I don't have the best link at my fingertips, but it's a clojure design decision to avoid java's native inheritence semantics, so you either get interfaces without default methods, or multimethods which do not reflect a native java feature
yep. I just recently “discovered” this same pattern when trying to think of a way to allow lib consumers to define custom keywords in a hiccup parser: https://github.com/Lokeh/hx/blob/master/src/hx/hiccup.cljs
the other thing you can do is pass in the actual implementation into the type constructor, and provide some higher-level functions with sane defaults for people who don’t care about the details
yes, you can manage about the right behavior with a hash-map full of functions that take an object as their first arg and merge / assoc for inheritance
In visualvm, all clojure repl's appear by default as "Clojure application". How would one get a project specific value to show up here?
by defining your own main method that launches a clojure repl - what's shown is the main method that is running in the vm
it would be a very small java program, but also it would be relatively pointless - the only advantage would be custom strings in jvm tooling, and there's multiple ways you could do it wrong
oh, fun trick
Hm if I have two records that refer to each other, how do I declare them
clojure is touchy about order of declarations
(defrecord A .... uses ->B)
and (defrecord B [^A parent])
How were you hoping to create a cycle between two immutable data structures via direct references? I don't know how to do that.
i.e. I think that is impossible.
No no... record A has a function that creates instances of B
and it selfinserts
If you weren't planning to do that, then perhaps defining defrecord A
first, then B
, but before A
put something like (declare ->B)
may work.
(->B this)
Tried declare it seems something breaks: CompilerException java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class, compiling:(introspect.clj:78:1)
instead of using ->B directly you can forward declare and call a function that calls ->B
since the method in A using B is protocol implementation I guess I could implement protocol for record lower
also, why not hint the protocol(s) that B implements instead of hinting B itself?
(if hinting is even needed...)
I'll just use extend-type
to add implementations later in code