This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-19
Channels
- # aleph (11)
- # aws (1)
- # beginners (14)
- # bitcoin (1)
- # boot (41)
- # cider (6)
- # cljs-dev (1)
- # cljsrn (13)
- # clojure (138)
- # clojure-italy (10)
- # clojure-nl (1)
- # clojure-poland (2)
- # clojure-russia (62)
- # clojure-sg (2)
- # clojure-spec (31)
- # clojure-uk (51)
- # clojurescript (109)
- # core-matrix (1)
- # core-typed (1)
- # cursive (63)
- # datomic (10)
- # emacs (9)
- # euroclojure (1)
- # hoplon (112)
- # immutant (16)
- # jobs (2)
- # lumo (5)
- # off-topic (14)
- # om (54)
- # onyx (17)
- # parinfer (23)
- # pedestal (2)
- # re-frame (41)
- # ring-swagger (23)
- # spacemacs (9)
- # specter (10)
- # uncomplicate (5)
- # vim (1)
I get a test/readme.clj
that's nearly 400 lines long -- mostly whitespace but it does have all the ``clojure` code fragments as tests
(hard to backtick a bunch of backticks)
heh, yeah, I ran into the same problem
cool =)
@seancorfield hm I don’t suppose you ever found a way to make that command exit with failure if a test fails?
also, wow, that found a lot of README errors XD
lein test
ought to get a non-zero exit status if tests fail? (Dunno, we switched to Boot ages ago at work)
Ah, but Midje doesn't. Yeah that kinda sucks.
I've always avoided Midje for... reasons... but I hadn't noticed it doesn't set an exit status in this case.
Maybe I'll write a Boot task that does something similar 😸
What’s the idiomatic way of ‘namespacing’ keys in a map?
I have a map, and I want to namespace all the keys in the map (same namespace)
#:person{:first "Han" :last "Solo" :ship #:ship{:name "Millenium Falcon" :model "YT-1300f light freighter"}}
Yeah, but that’s using a map literal.
What if I already have a map.
with regular clojure you’re gonna have to do the usual for-loop dance (or something like it):
(into {} (for [[k v] your-map] [(keyword (name k) "your-ns") v]))
(with-meta (first {:foo :bar}) {:foo :bar})
=> ClassCastException clojure.lang.MapEntry cannot be cast to clojure.lang.IObj clojure.core/with-meta--4962 (core.clj:217)
Is it a bug?
My workaround is (with-meta (first (map vec {:foo :bar})) {:foo :bar})
@souenzzo Nope, map is unordered, so there's no "first", technically speaking. Since vec is ordered, you get your first element. The problem is when there's more elements and you convert to vec, you'll get first somewhat randomly (not sure exactly how order is defined) Discard that, not the case.
@souenzzo another alternative would be (into ^{:foo :bar} [] (first {:foo :bar}))
but using first on a hash map is a code smell - it could for example be a sign that the data doesn't belong in a hash map, or that you are not looking something up the right way *fixed
that's putting the meta on a new vector and then emptying the map-entry into it
I'm not doing (with-meta (first ..)
... it's just a minimal/synthetic example 😜 In my case, I have a function that do some like (map #(with-meta {:type t} %) my-seq)
. Then I think that should work with maps too (once maps in clojure are "mappable").
only if you put each map entry into a vector
but yeah
so my version would be (map #(into ^{:type t} [] %) m)
Anyone here using http://nd4j.org/ ? This library shows up first for "java ndarray", but reading the docs, this project seems to have a very high opinion of itself (and I can't find other people using it.)
Is following "thread safe"? Can there be a race condition?
(reset! db @db)
e.g. changed db
value between deref
and reset!
for the behavior you want, use http://clojuredocs.org/clojure.core/compare-and-set!
but can i get the timings of the calls to foo-1,foo-2,foo-3 without wrapping each fn?
@jooivind have a look at https://github.com/thunknyc/profile
what would be a use case for this? https://github.com/weavejester/medley/blob/1.0.0/src/medley/core.cljc#L273
same as swap!
, but returns atom's previous value (before it was successfully swapped)
(def queue (atom clojure.lang.PersistentQueue/EMPTY))
(defn push! [x]
(swap! queue conj x))
(defn pull! []
(-> queue (deref-swap! pop) peek))
Hello everyone, I have an app which stores documents (edn/json files, size from 100kb up to 1000kb) and I want to save the whole change-history (changes will be small, max 30kb maybe, but frequently) without storing the whole document for each change. Is there a free document database which supports document history with delta encoding?
@jcf yes, datomic looks promising, but the licensing doesn't fit. (only 1 year updates in free version etc.) @leonoel I heard this from other people before. It sounds logical, but odd to use git as a "database" 😀 Maybe I should give that idea a try. The documents are hold in-memory at runtime, and only written on disk if changes were made - so using git seems to be a good solution.
there's irmin, but I am not sure there's a binding for java, it should not be impossible to do tho
trying to do that, but this is for serializing part of an ExceptionInfo object to an exception tracker
and I don't want to completely lose the information, but I would be satisfied by an encoder that just did pr
@bbloom don't you have some sort of 'local multimethod' gist somewhere? for non global-dispatch tables
in tools.analyzer I used a combination of dyn var initialized to a wrapping default fn and multimethods to allow extensibility through multimethods
the pattern I used is e.g.
(defmulti -foo dispatch-fn)
(def ^:dynamic foo* -foo)
(defn foo []
(foo* ..))
example setup: https://github.com/clojure/tools.analyzer/blob/master/src/main/clojure/clojure/tools/analyzer/passes/emit_form.clj#L12-L30 and redef: https://github.com/clojure/tools.analyzer.jvm/blob/master/src/main/clojure/clojure/tools/analyzer/passes/jvm/emit_form.clj#L14-L46
@bja I have a small wrapper around Jackson that I used to parse instead of cheshire https://github.com/ghadishayban/tinyjson/blob/master/src/ls/tinyjson/json.clj#L60-L138 The writing side of it I used a protocol, which was a mistake. Feel free to fork or PR
I should have done a dispatch impl like https://github.com/cognitect/transit-clj/blob/master/src/cognitect/transit.clj#L88-L123
also likely out of date w/ any bug fixes or perf improvements that happened in clj/core
that’s not a syntax
but it’s a valid binding or def
clojure has very few syntaxes, the ones that are symbols usually start with #
@mnzt if you tell us where you find it that might be a clue to what it means though
@mnzt as a random guess, you're probably looking at code that uses the swiss arrows library
I've just seen it around and was curious, doesn't appear to be swiss arrows, and here's some linkable code https://github.com/metabase/metabase/blob/master/src/metabase/api/metric.clj#L44-L47
@mnzt that’s just a binding that as-> sets up
check out the doc for as->
it’s just a name they picked, you could find/replace it with elephant
and the meaning of the code wouldn’t change
though x
would be more idiomatic, and <>
is a nice symbol for “fill in the blank” once you know what it means
we're having trouble finding docs on the exact meaning of the #=
macro anywhere, anyone know where to find that?
@timsgardner it’s the read-eval reader macro, which causes arbitrary code to execute while reading, it’s disreccomended
the core read will eval if the right dynamic var is set and it finds that macro, clojure.edn’s read will not though
it's not officially supported according to the only docs I can find https://clojure.org/guides/weird_characters#__code_code_reader_eval
aha, thanks for that link
what's the currently favored HTTP server library you guy are using? It seems Aleph and http-kit are favorites. Anything else I'm missing?
@beders I use Pedestal quite a bit, and I like it.
We just use jetty
if that’s the layer you’re asking about
Yeah, on that layer I highly recommend using a well established library like Jetty. It removes a lot of questions from debugging sessions.
Yup, agree on Jetty, although I prefer Netty (I did a bunch of work with Vert.x, so I'm familiar with async web servers). I was wondering which wrapper you guys are using for creating a REST endpoint (or GraphQL for that matter), registering something like routes/handlers (or do it Resource-style like in Jersey)
aha, we’re using compojure-api
last shop I was at used it too
particularly interested in support for full async operation and reasonable standards-support like CORS, JWT etc.
it generates swagger specifications from your code, which is pretty nice
Aleph
Really like it, it makes perfect sense. http://aleph.io
Uses Netty, btw
Oh, sorry: yada
yada uses aleph
@beders Pedestal and Aleph are the only ones that support full async. IMO Pedestal is a bit simpler in design.
I like yada as well. It has built-in support for swagger and jwt. More importantly I find it well designed 🙂
compojure's 2.0-alpha releases support async as well but currently only works out of the box with ring-jetty. I haven't tried it out, but you should be able to bootstrap it onto Aleph, HttpKit, or Undertow. See here: https://github.com/metosin/compojure-api/wiki/Async
Quick quesiton: cljs-ajax's documentation makes it sound like it can be used both clientside in CLJS and server-side in clojure, but when I try I get errors like No implementation of method: :-js-ajax-request of protocol: #'ajax.protocols/AjaxImpl found for class: ajax.apache.Connection
, which makes it sound like it won't work on the server side. Am I missing something here, or is it actually CLJS only? I know I could just use clj-http on the server, but that will mean some duplicated code between the client/server side instead of putting it in cljc.
likely you recompiled the file that defined the protocol without recompiling the file that extends the record
the record code also imports the interface generated by the protocol and uses that instead of actually using the protocol
that a project as active as that, with that many contributors, can have that kind of error in it makes me sad
I'm afraid I don't have a good grasp of how protocols and records work. Is this something I should submit an issue for then?
Looks like you were right about the compilation issue. Restarting the repl from scratch did clear the error.