This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-13
Channels
- # arachne (2)
- # architecture (23)
- # bangalore-clj (5)
- # beginners (35)
- # boot (79)
- # cider (6)
- # cljs-dev (34)
- # cljsrn (9)
- # clojure (164)
- # clojure-argentina (2)
- # clojure-austin (4)
- # clojure-italy (7)
- # clojure-russia (40)
- # clojure-serbia (1)
- # clojure-spec (76)
- # clojure-uk (36)
- # clojurescript (47)
- # cursive (14)
- # datascript (2)
- # datomic (8)
- # dirac (19)
- # emacs (29)
- # heroku (7)
- # hoplon (35)
- # jobs-rus (1)
- # juxt (2)
- # leiningen (1)
- # lumo (23)
- # mount (4)
- # off-topic (22)
- # om (16)
- # onyx (19)
- # parinfer (10)
- # pedestal (47)
- # proton (5)
- # re-frame (88)
- # rum (1)
- # spacemacs (33)
- # sql (29)
- # uncomplicate (1)
- # unrepl (131)
- # untangled (5)
- # yada (12)
If it's not in the spec, it's not part of the spec
The code may support more than the spec
If I want a websocket client for clojure (ie not cljs/browser), is aleph the best option? or only option? Google isn't giving me much
I like to use ctor
@qqq ‘ctor' is a pretty standard abbreviation for ‘constructor’ https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)
Is there a way for me to turn a keyword into a fn if I have function of a similar name (e.g. :and -> and) ?
Probably a huge hack by you can do something like
(defn kw->fn [kw]
(->> (name kw)
(str "clojure.core/")
(read-string)
(eval)))
thanks @fernandohur
user=> (kw->fn :+)
#<Fn@17b88c84 clojure.core/_PLUS_>
You will need to supply the namespace where your function lives.
user=> (ns-resolve (symbol "clojure.core") (symbol "+"))
#'clojure.core/+
Yep, looks like that one works:
user=> ((ns-resolve (symbol "clojure.core") (symbol "+")) 1 2 3)
6
Hey guys, I made a little nlp parser with some models in french - would appreciate your feed-back
can someone help me understand this compile error? Exception in thread "main" clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec: In: [0] val: intermine.dg.repl/-main fails at: [:args :name] predicate: simple-symbol? :clojure.spec/args (intermine.dg.repl/-main) #:clojure.spec{:problems [{:path [:args :name], :pred simple-symbol?, :val intermine.dg.repl/-main, :via [], :in [0]}], :args (intermine.dg.repl/-main)}, compiling:(/tmp/form-init6404384847914733184.clj:1:294)
the name you gave to ns
is not a simple symbol... what is the code that caused the error?
actually i think it's saying that the -main function declaration is not right, sorry about that
yeah, i think you're right. i trimmed it down to a simple
(defn -main [& args]
(println "Building client..."))
with no luckwell, I don't know what it is -- but since you posted that, maybe change the (while true)
which takes 100% cpu in its time slice to something which blocks instead, to keep your main
from returning. maybe @(promise)
and i see nothing wrong with what you posted as far as structure -- as a sanity check, are you sure that what you posted is what's actually running to cause the error?
what does datomic/datascript/datalog lack that SQL has given (1) how simple datascript/datomic/datalog query language is and (2) how complicated SQL query language is?
@qqq Datomic does push you to do more work in the app code. I think that's a nice feature, but some may disagree. So in other words, SQL has fast efficient ways of sorting, grouping, etc. With Datomic you're a bit at the mercy of the developers and the language in use.
I haven't had too much of an issue with that, but doing "SELECT count(*) FROM users GROUP BY users.location HAVING count(users.location) > 10" is a bit more involved in a non-SQL db.
Personally I find that a small price to pay for all the other benefits Datomic gives you though.
tbaldridge: (1) I'm using datascript instead of datomic, (2) I'm starting to feel another feature is datascript/datomic query feels like "the same language" since it's just EDN, whereas with SQL, even with the best bindings, it still feels like a 2nd langauge
@tbaldridge: also, noting that your response may be biased -- how does odin & datascript compare?
the two seems very similar in that (1) there's an eav store (2) there are indezes (3) there is a query language that is closer to datalog than core.logic
Hi! Is anybody know workaround for this http://dev.clojure.org/jira/browse/CLJ-1625 ? I use reify with two protocols with equal method signature.
@qqq it's a question of being set-based vs lazy. Odin is a lazy query engine. Datascript and Datomic are set based, meaning they always get all the results. They are faster because of that, but your full dataset has to reside in memory. That being said, I've run a Odin-like engine on top of Datomic and it works really well.
(ns quester.use-cases.protocols.persistence.selections)
(defprotocol Cards
(-selections--cards [_ limit]))
(defn cards [ctx & {:keys [limit]}]
(-selections--cards ctx limit))
you'll have to rename one of them... whatever is the simplest for resolving the conflict
@tbaldridge Did you by any chance pass along the bug in transit-ruby mentioned the other night? The one about it having trouble reading a transit file created using multiple transit-ruby writes where Clojure's transit doesn't have a problem.
probably filing an issue is the best way to go about that, @devn, IIRC there were some issues like this in the Python version, and I think Ruby as well
basically some JSON readers assume that if you call (read-json some-stream)
, that they are free to read past the end of the first element. That they have full control of the stream for now on.
@tbaldridge ah, yeah, that sounds about right in ruby
@tbaldridge when we were talking about multiple reads, I wound up with this:
(def new (atom []))
(with-open [in (io/input-stream "file.transit")]
(let [reader (transit/reader in :json)]
(loop [avail? (pos? (.available in))]
(if avail?
(do (swap! new concat (transit/read reader))
(recur (pos? (.available in))))
:done))))
yep, or just keep reading until you get an IOException
@tbaldridge yeah that felt dirty
@tbaldridge does that concat
give you pause?
I'd probably use into
and rework it to get rid of the atom, but that's about it.
Don't concat
in a loop https://stuartsierra.com/2015/04/26/clojure-donts-concat
I tried to slap a subset of datomic’s datalog on top of sqlite and wrote somewhat clunky datalog->sql compiler, turns out it works pretty well 😄
nice — i was thinking of making a pull expression interpreter for a nasty third party api we have to deal with
@tbaldridge yeah, pretty much, but not exactly - it had one huge table for datoms and naively ran a ton of “recursive common table expressions" on it, pushing all the work to sqlite. I couldn’t be bothered to write any kind of unification engine, despite binge watching your youtube content 🙂
turns out that sqlite is quite good at optimizing these things and most queries couldn’t make it sweat
With specter, how can I do the moral equivalent of a mapcat in a transform? I’m updating a deeply nested vector, but each element will turn into some number of elements.
@lvh this is the start of a navigator definition that does that:
(defnav ALL-ELEM-SEQ []
(select* [this structure next-fn]
(doseq [e structure]
(next-fn [e])))
(transform* [this structure next-fn]
(mapcat (fn [e] (next-fn [e])) structure)
))
the transform case needs to be extended to maintain the type of the input sequence
basically it just navigates you to each element as a one-element vector
@nathanmarz A question I’ve been meaning to ask you about Specter for a while: what was the motivation for the UPPERCASE naming of certain things?
I just wanted to distinguish navigators from regular functions
since functions are interpreted as filter navigators within a Specter path
for awhile it was just ALL
, and then for consistency I stuck with the naming convention as I found more use cases
It’s probably the thing I’ve found most jarring about Specter whenever I’ve looked at the examples… I guess it would be hard to change now...
if you want a different naming convention you can just do (def ALL <all>)
or whatever
Good point. I haven’t had a chance to take it for a test drive yet. It’s “on my list”.
It may be a while. We don’t have the sort of data structures at work that would benefit from Specter, as far as I can see, so this will be a hobby / side project to evaluate it.
I have a macro that throws can throw an AssertionError during expansion. I can test this expectation like this (is (thrown? AssertionError (macroexpand-1 '(my-macro))))
or (is (thrown? AssertionError (#'my-macro-impl)))
. Both of these pass when I run them from Cursive, but they fail when I run lein test
. Any ideas?
the first thing I would do, I think, would be to stop using thrown?
since it isn't a thing you can check. so I would replace thrown?
with something like (try whatever false (catch SomeException e true))
and then I would try that expression in different contexts
When I run all of the tests, it says "ran 2 tests, 27 assertions". Then when I comment out the testing
blocks that fail when ran with lein test, cursive says "ran 2 tests, 19 assertions".
when you print out the assertion values right before the assert, when you run lein test, does it print out values that should fail?
are you disabling asserts in your project.clj? there is a dynamic var that disables them at compile time, and maybe cursive doesn't understand that
Hmm so, the macro is basically an extended form of defn. I have a bunch of tests for it, but most of them are about actually using the macro, not just seeing if it expands properly (hope that makes sense). When I added printing before the assert that is supposed to fail, the printing works when calling the tests without expansion, but I see no printing when I run the tests that just see if the macro expands or not
I also edited one of the earlier tests to call the macro in a way that is not accepted. Now I can't run the tests in cursive or in the repl (the code doesn't compile). So I guess that means assertions do work.
so if it isn't executing the println where you think it should be, you can move backward from there inserting more printlns until you find a place where code is actually getting run
to unit test a macro, don’t you need to call eval inside the test?
(the expansion of a macro, that is)
kauko are you sure you running lein test in the same project as you are editting in cursive?
@kauko I recommend putting the macro code in a defn, and then testing the output of that defn. Debugging stuff that dies inside the compiler (as macros do) is always tough
@tbaldridge that’s an excellent suggestion
lol I forget who I tell what to
@hiredman if folder = project, then yes. If by project you mean something else, then I'm not sure 🙂
so you can keep putting in printlns working backwards, before each place the macro is used, till you get to a place that is actually executed
Now the problem is just that when I run the test with lein test, a RuntimeException is thrown. In the cursive, it's still an AssertionError. 😄
@hiredman @tbaldridge @U051SS2EU just wanted to let you know I got it to work. The answer was (is (thrown? AssertionError (eval '(
So pretty much like noisesmith said 🙂 Sorry for the pings!
hello, how do you immitate a request with a modified media-type (a.k.a mime type)? tried ...
(let [response (->
(handler (request :get "/"))
(content-type "text/html")
(header "Content-Type" "text/html")
(header "Accept" "text/html"))] ...
... but the response still returns plain/text (meaning the request sent with the mime types were ignored)I think this comes down to the middleware you’re using…?
According to ring.util.response docs, you shouldn’t need to call both content-type
and header “Content-Type”
?
FWIW, here’s what I see from just using ring.util.response
: https://www.dropbox.com/s/05omumcwhuw6v6k/Screenshot%202017-03-13%2013.43.29.png?dl=0
So content-type
adds the header as expected, calling just header “Content-Type”
sets the header as expected (not shown in that screen cap — but tested in the REPL), and calling both leads to the same result — so I’m not quite sure what’s causing your issue… what exactly does your handler return @U3J70EL7K ?
helloe seancorfield , sorry late reply, the problem I was having is when I send a request using ring.mock.request
,
I simply want to alter the header sent (`"Content-Type"` in this case), so I tried each of them one by one, then finally send all of them at once, still no difference because the server still responds to plain/text, but if I access the url using a browser, it returns the correct media type (text/html).
Here's the main file: https://github.com/ejelome/blog-clj/blob/master/src/blog/core.clj
And here's the problematic test: https://github.com/ejelome/blog-clj/blob/master/test/blog/core_test.clj
I skipped the experiment last night because I was so tired I just slept, but the main goal in the test is to send different media types (a.k.a. mime types) so I can see test and see each of their responses properly.
the test above btw doesn't show the problematic scenario, but just to show how I do the test
You have a lot of moving parts in there — and several that I’m not familiar with (Midje, Liberator, etc) — and I’d have to read up on Ring’s mock to figure out what’s going on there. Unlikely I’ll have time to pick up all of that this week. Sorry.
hello seancorfield, no worries, you've already gave some great clues, thanks for the help 🙂
@kauko paste a stack trace?
or perhaps the code + stacktrace? Most of the time the stacktrace shows the truth, even if it is a bit opaque
Here:
... :content-type "text/html", :headers {"Content-Type" "text/plain;charset=UTF-8", "Vary" "Accept", "accept" "text/html", "content-type" "text/html"}, :status 200}
Perhaps a thread would be a good idea for a long, involved mostly 1:1 debugging session? Just a thought /admin-hat-on
(that was odd — I shared a DropBox link in a thread, but Slack loaded the preview into the main channel… a bug in threads I think!)