Fork me on GitHub
#clojure
<
2018-03-15
>
didibus04:03:40

Just tried unravel, and I'm amazed. Unrepl should really become the standard.

Empperi08:03:27

Hmm, does anyone know how to check a map with clojure test in such a way that you can define some of the values to be anything? I know midje can do this but looking for an alternative for clojure test

Empperi08:03:04

I can of course dissoc the specific keys out and do the comparison there but that is noisy and confusing to read

jumar08:03:19

@niklas.collin select-keys might be a bit more explicit than dissoc.

Empperi08:03:43

not happy with that either. Especially since the value in this case is within nested map

tianshu08:03:38

Any user of eastwood here? I want do exclude-linter in the config file(not project.clj). can't found any example on this, neither there's a #eastwood channel.

Empperi08:03:13

looking at core test sources, it looks like I can expand the is macro by defining new values to assert-expr multimethod

Empperi08:03:06

I could theoretically make something like ~= or whatever which would recognize specific values as map values and accept anything there

rauh08:03:41

@niklas.collin Maybe:

(let [m {:a 2, :c 3, :other 4}]
  (are [key val] (= (key m) val)
    :a 2
    :c 3))

Empperi08:03:17

definitely would not fly due to amount of keys plus due to the fact this is a nested map

Empperi08:03:49

I think I'll try to extend the assert-expr with a generic approach

Empperi08:03:55

so I could write something like:

rauh08:03:56

Well just modify the expression to use get-in and maybe treat ::any as a special value

rauh08:03:20

Give us a full example 🙂

Empperi08:03:45

(is (~= (do-something)
        {:foo {:bar ::any}}))

Empperi08:03:17

or whatever the name for that comparison function would be

mpenet09:03:06

seems like spec could be a decent solution for this, since s/keys are open

Matthias Schuster10:03:29

The JVM and .NET both don’t like that TCO removes stack frames while loops have no stack frames at all, so why does this matter?

gnejs10:03:56

@niklas.collin maybe using something like (defn partial-match [actual expected] (= expected (last (clojure.data/diff expected actual)))) ? (slightly untested)

Jakub Holý (HolyJak)12:03:18

For those wondering whether Clojure is an obstacle or an advantage regarding hiring, read about our experience: http://techblog.telia.no/blog/experience-report-hiring-for-clojure-script-is-easy/

seancorfield15:03:50

I would recommend follow-up in #jobs-discuss

jduhamel17:03:31

I have a binary file with a defined Start Record , End Record, What’s the idiomatic way to read the records into a list or a lazy seq? Is there a library I should be looking at?

hiredman17:03:31

huh, the gloss repo has been archived

mpenet17:03:19

never heard of github archives

noisesmith17:03:41

I'd be interested to know why it was archived

hiredman17:03:36

zach is a busy guy I guess

tetriscodes18:03:06

Whats the channel to ask a repl refresh question?

tetriscodes18:03:48

(use '[clojure.tools.namespace.repl :only (refresh)]) calling (refresh) has trouble loading namespaces that loaded fine before.

hiredman18:03:49

the dependency analysis that tools.namespace does is almost like a linter

hiredman18:03:50

there is all kinds of weird jiggery pokery you can get clojure to load, or just happens to load most of the, but tools.namespace is stricter about what it accepts

hiredman18:03:24

which is to say, I would check you namespaces to make sure they form a nice DAG

hiredman18:03:17

make sure you aren't using require or import outside of the ns forms, and that if you are using any jvm types that are generated from clojure code that you are properly requiring that clojure code before attempting to use the types

ajs18:03:37

I’ve got a 300MB JSON file I want to make into a Clojure map. I can’t just slurp it, it get Out of Memory at the REPL. Increasing the memory limit in my project by using variations of :jvm-opts ["-Xmx1000M"] makes no difference. Any suggestions how to approach it?

hiredman18:03:02

don't use slurp

hiredman18:03:14

(assuming you mean clojure.core/slurp)

ajs18:03:29

what’s the alternative?

ajs18:03:33

with-open?

ajs18:03:50

The entire file is a single JSOn object, so it needs to read it all regardless of function, does nit?

hiredman18:03:12

yeah, but slurp is the least efficient way to do anything you would want to do with slurp

hiredman18:03:22

depending on what kind of data it is, I wouldn't be surprised if it is significantly larger deserialized

hiredman18:03:59

all your strings will likely double is byte count (some newer jvms can do things to try and avoid this)

juhoteperi18:03:13

There are ways to read JSON efficiently: https://github.com/FasterXML/jackson-docs/wiki/JacksonStreamingApi Not sure what Cheshire uses/how it usually works, but it is possible.

ajs18:03:08

trying something like this

(def t (with-open [rdr ( "filte.json")]
               (json/read-str (apply str (line-seq rdr)))))

ajs18:03:23

but that still gives me the out of memory

ajs18:03:13

that snippet works on smaller json files

ajs18:03:28

if the json file is 300MB, wouldn’t an increase in the jvm memory of 1 GB be enough?

ajs18:03:28

ah, i gave it 2 GB and it worked. all that for a 300 MB file.

john18:03:34

Once you're getting that big, it's better not to work on the whole thing at once

triss19:03:10

what’s the idiom for take-until? like a take-while but includes the first element of the list that fulfils pred?

qqq20:03:09

What would it take to create PyTorch bindings for Clojure? I'm not asking about Clojure alternatives to PyTorch. I want the full powedr f PyTorch -- accessible from the Clojure repl. What do we need to do to make this happen?

the2bears20:03:54

@qqq not that familiar with Python (actually not really at all) but are you thinking of a binding to run PyTorch in the Python VM(is it one?) through Clojure?

qqq21:03:04

@the2bears: I'm not familiar with Python either, but I really need PyTorch and it's tensor support.

qqq21:03:25

It's insane that from Clojure, it is easier to use Cuda than it is to use PyTorch.

qqq21:03:59

https://dragan.rocks/articles/18/Interactive-GPU-Programming-3-CUDA-Context confuses me regarding a 'repl threadpool' 1. Is there an actual threadpool for clojure repls ? 2. When I do a cider-jack-in and send exprs via C-x C-e, am I always hitting the same thread every time, or am I getting different threads? 3. Is this issue due to the author using org-modce blocks of code, or does it effect those using cider-jack-in too ?

noisesmith21:03:15

nrepl has its own infrastructure which isn't clojure.core, I wouldn't be surprised if it used a threadpool

the2bears21:03:07

@qqq if my memory serves me, there was some discussion awhile back on accessing R and Python from Clojure in the #data-science channel but it's long gone now.

JJ22:03:28

is 'clj -i my.ns -r' the same as entering the repl and doing (require 'my.ns) ?

seancorfield22:03:28

@devicesfor The -i option to clj specifies a file path (or resource path) and it loads that for initialization.

seancorfield22:03:43

I think you would want

clj -e "(require 'my.ns)" -r
to start a REPL with my.ns already required.

seancorfield22:03:59

If you want to start the REPL in that namespace

clj -e "(require 'my.ns) (in-ns 'my.ns)" -r

JJ22:03:36

was doing clj -i ns.clj -e "(in-ns 'my.ns)" -r

JJ22:03:04

@seancorfield but is the end result different?

JJ22:03:45

for ex: does require just calls load?

seancorfield22:03:40

No, but I suspect for your purposes, it'll do what you need.

seancorfield22:03:48

Given that in a "normal" project structure, your file would be src/my/ns.clj for (require 'my.ns), you'd need clj -i src/my/ns.clj ...

JJ22:03:49

yes, just curious about the difference

JJ22:03:57

between the two

seancorfield22:03:35

Which goes to this line (if the lib isn't already loaded and you didn't ask for :reload-all): https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5863 which is (load (root-resource lib))

seancorfield22:03:00

And root-resource deals with the mapping between - and _; . and /; and the classpath-relative aspect (`src/` in the example above).

seancorfield23:03:13

So... aside from the namespace<->filename mapping and the *loaded-libs* stuff (and all the options to require), underneath it all there's a load call 🙂

seancorfield23:03:03

(hmm, that's the first time I've seen the new GitHub integration in play -- nice that it pulls in the actual source code now!)

noisesmith23:03:00

it looks pretty bad in the weechat client, but at least the href link still works

hmaurer23:03:17

Hello! Quick question: I would like to def a bunch of functions in the namespace which are all slight variant of existing functions. Basically I would like to loop over the name of some existing functions and define new functions with a prefixed name which wrap calls to the existing functions

hmaurer23:03:22

how can I metaprogram this?

seancorfield23:03:52

@hmaurer Sounds like a pretty straightforward macro, depending on exactly what you're trying to do...

hmaurer23:03:15

@seancorfield I was thinking of using the intern function, but that doesn’t seem idiomatic. How could I do it with a macro? To keep it simple for now, let’s say I have a vector with names of functions I want to wrap, and I want to define new functions prefixed with wrapped- which wrap calls to the said functions. All have arity 1 (a single parameter)

seancorfield23:03:17

The macro would loop over the names and do a defn for each one with the wrapped name and body.

seancorfield23:03:46

For example:

(defmacro wrap [& names]
  (cons 'do (for [n names] `(defn ~(symbol (str "wrapped-" (name n))) [arg#] (inc (~n arg#))))))
Then if you have
(defn foo [x] (* 2 x))
and you do
(wrap foo)
you will get a wrapped-foo function that increments the result of calling foo.

seancorfield23:03:13

That could probably be cleaner...