Fork me on GitHub
#clojure
<
2017-07-19
>
seancorfield00:07:59

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

seancorfield00:07:27

(hard to backtick a bunch of backticks)

michaelblume00:07:14

heh, yeah, I ran into the same problem

michaelblume00:07:27

@seancorfield hm I don’t suppose you ever found a way to make that command exit with failure if a test fails?

michaelblume00:07:16

also, wow, that found a lot of README errors XD

seancorfield00:07:47

lein test ought to get a non-zero exit status if tests fail? (Dunno, we switched to Boot ages ago at work)

seancorfield00:07:23

Ah, but Midje doesn't. Yeah that kinda sucks.

seancorfield00:07:17

I've always avoided Midje for... reasons... but I hadn't noticed it doesn't set an exit status in this case.

seancorfield00:07:59

Maybe I'll write a Boot task that does something similar 😸

stuartrexking00:07:51

What’s the idiomatic way of ‘namespacing’ keys in a map?

stuartrexking00:07:57

I have a map, and I want to namespace all the keys in the map (same namespace)

beders00:07:32

#:person{:first "Han" :last "Solo" :ship #:ship{:name "Millenium Falcon" :model "YT-1300f light freighter"}}

beders00:07:40

you mean like this?

stuartrexking00:07:57

Yeah, but that’s using a map literal.

souenzzo01:07:17

+1 to "namespace utils" for datomic, like "split-by-namespace" and "qualify-map"

stuartrexking00:07:04

What if I already have a map.

schmee06:07:00

with Specter:

(s/setval [s/MAP-KEYS s/NAMESPACE] "your-ns" your-map)

schmee06:07:22

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

souenzzo01:07:21

(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})

alex-glv02:07:31

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

noisesmith02:07:02

@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

noisesmith02:07:37

that's putting the meta on a new vector and then emptying the map-entry into it

souenzzo02:07:37

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

noisesmith02:07:39

only if you put each map entry into a vector

noisesmith02:07:24

so my version would be (map #(into ^{:type t} [] %) m)

qqq07:07:27

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

misha09:07:33

Is following "thread safe"? Can there be a race condition?

(reset! db @db)
e.g. changed db value between deref and reset!

schmee09:07:25

the value can change

jooivind09:07:43

Is there a way to time all sub-calls of a fn?

jooivind09:07:26

let’s say i have:

(defn foo [x]
         (-> (foo-1 x)
               foo-2
               foo-3))

jooivind09:07:42

ofc i can do

(time (foo x))

jooivind09:07:01

but can i get the timings of the calls to foo-1,foo-2,foo-3 without wrapping each fn?

razum2um10:07:33

Is there any way (lib?) to rerun only “failed-last-time” clojure.test vars?

misha12:07:08

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)

leonoel12:07:07

@misha

(def queue (atom clojure.lang.PersistentQueue/EMPTY))

(defn push! [x]
  (swap! queue conj x))

(defn pull! []
  (-> queue (deref-swap! pop) peek))

burke14:07:03

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?

jcf14:07:16

@burke Datomic comes close to doing what you want, but it's not an exact match.

burke14:07:31

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

mpenet14:07:22

there's irmin, but I am not sure there's a binding for java, it should not be impossible to do tho

bja15:07:05

is it possible to do local type extension?

bja15:07:12

i.e. extend something only in a let binding?

a1315:07:36

(let [wtf (extend-fn wtf)]
 …
?

ghadi15:07:13

@bja nope. What are you trying to achieve?

bja15:07:30

locally I want to encode JSON differently

bja15:07:51

was just looking through how cheshire.generate maps encoders via a protocol JSONable

ghadi15:07:45

I see. Unfortunately cheshire write methods are global =(

ghadi15:07:02

Transit and Fressian do not make that mistake

ghadi15:07:12

( i know that doesn't help you immediately )

bja15:07:19

unfortunately my third party api doesn't accept either of those

bja15:07:12

I wonder if data.json is extensible locally

ghadi15:07:49

can you convert prior to sending down to cheshire?

ghadi15:07:35

we should have a new json library that does write dispatch the same way transit does

bja15:07:44

trying to do that, but this is for serializing part of an ExceptionInfo object to an exception tracker

ghadi15:07:46

not global protocols but per instance maps

bja15:07:49

so sometimes I get things like Fns

bja15:07:25

and I don't want to completely lose the information, but I would be satisfied by an encoder that just did pr

bja15:07:42

but I don't want to just (cheshire.generate/add-encoder Object pr) globally

ghadi16:07:49

@bbloom don't you have some sort of 'local multimethod' gist somewhere? for non global-dispatch tables

bja16:07:09

@ghadi I have one of those too for testing purposes

ghadi16:07:09

maybe that was @bronsa ?

bja16:07:20

that lets me clone a multimethod

bja16:07:25

for local modification

bronsa16:07:21

in tools.analyzer I used a combination of dyn var initialized to a wrapping default fn and multimethods to allow extensibility through multimethods

bronsa16:07:32

the pattern I used is e.g.

(defmulti -foo dispatch-fn)
(def ^:dynamic foo* -foo)
(defn foo [] 
  (foo* ..))

bronsa16:07:13

not the prettiest of patterns but it gets the job done

ghadi16:07:00

@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

bbloom16:07:47

@ghadi github: dispatch-map

bbloom16:07:55

warning: never actually used in anger

bbloom16:07:32

also likely out of date w/ any bug fixes or perf improvements that happened in clj/core

mnzt18:07:45

Hey can someone point me to the name of this syntax <> please? It's a pain to Google!

noisesmith18:07:14

that’s not a syntax

noisesmith18:07:21

but it’s a valid binding or def

noisesmith18:07:52

clojure has very few syntaxes, the ones that are symbols usually start with #

noisesmith18:07:30

@mnzt if you tell us where you find it that might be a clue to what it means though

bfabry18:07:52

@mnzt as a random guess, you're probably looking at code that uses the swiss arrows library

bfabry18:07:34

(googling "swiss arrows clojure" will tell you if that's true)

mnzt18:07:28

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

noisesmith18:07:58

@mnzt that’s just a binding that as-> sets up

noisesmith18:07:03

check out the doc for as->

noisesmith18:07:22

it’s just a name they picked, you could find/replace it with elephant and the meaning of the code wouldn’t change

mnzt18:07:43

👌 Perfect, thanks a lot 🙂

mnzt18:07:23

A lot to take in coming from Golang as a primary language 😄

noisesmith18:07:50

though x would be more idiomatic, and <> is a nice symbol for “fill in the blank” once you know what it means

hiredman18:07:51

I like to use % with as->

timsgardner20:07:02

we're having trouble finding docs on the exact meaning of the #= macro anywhere, anyone know where to find that?

noisesmith20:07:30

@timsgardner it’s the read-eval reader macro, which causes arbitrary code to execute while reading, it’s disreccomended

noisesmith20:07:11

the core read will eval if the right dynamic var is set and it finds that macro, clojure.edn’s read will not though

bfabry20:07:13

it's not officially supported according to the only docs I can find https://clojure.org/guides/weird_characters#__code_code_reader_eval

timsgardner20:07:37

aha, thanks for that link

beders20:07:08

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?

tbaldridge20:07:42

@beders I use Pedestal quite a bit, and I like it.

michaelblume20:07:52

We just use jetty

michaelblume20:07:02

if that’s the layer you’re asking about

tbaldridge20:07:52

Yeah, on that layer I highly recommend using a well established library like Jetty. It removes a lot of questions from debugging sessions.

beders20:07:13

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)

michaelblume20:07:27

aha, we’re using compojure-api

michaelblume20:07:40

last shop I was at used it too

beders20:07:51

particularly interested in support for full async operation and reasonable standards-support like CORS, JWT etc.

michaelblume20:07:58

it generates swagger specifications from your code, which is pretty nice

beders20:07:18

ah: swagger, pseudo-REST 😉

kurt-o-sys21:07:02

Really like it, it makes perfect sense. http://aleph.io

kurt-o-sys21:07:33

Uses Netty, btw

kurt-o-sys21:07:25

Oh, sorry: yada

kurt-o-sys21:07:35

yada uses aleph

tbaldridge21:07:25

@beders Pedestal and Aleph are the only ones that support full async. IMO Pedestal is a bit simpler in design.

beders21:07:51

thanks everyone!

nha21:07:14

I like yada as well. It has built-in support for swagger and jwt. More importantly I find it well designed 🙂

bja22:07:53

compojure-api on top of Undertow (via immutant.web)

bja22:07:34

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

tjscollins23:07:05

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.

hiredman23:07:27

likely you recompiled the file that defined the protocol without recompiling the file that extends the record

hiredman23:07:48

the record code also imports the interface generated by the protocol and uses that instead of actually using the protocol

hiredman23:07:21

which is common way to break things like this

hiredman23:07:35

that a project as active as that, with that many contributors, can have that kind of error in it makes me sad

tjscollins23:07:38

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?

hiredman23:07:41

I am typing up an issue

tjscollins23:07:13

Looks like you were right about the compilation issue. Restarting the repl from scratch did clear the error.