Fork me on GitHub
#clojure
<
2016-03-09
>
virmundi02:03:27

@shaun-mahood: thanks

alexmiller02:03:34

@virmundi: I like the immuconf approach to using edn myself

roberto02:03:34

i like immuconf too

roberto02:03:45

i highly recommend it

urbanslug07:03:07

What does ^ mean in a project.clj?

smw07:03:22

Can you give a line of context?

smw07:03:39

:clean-targets ^{:protect false}

smw07:03:59

That is setting metadata.

josh.freckleton15:03:16

Is there a more idiomatic way to apply a function on every cell in a grid than this?: (map (fn [row] (map (fn [cell] (/ 1 cell)) row)) grid)

donaldball15:03:47

I’d probably write a fn so I could do (update-cells grid (partial / 1))

blueberry15:03:11

depends on how you represent a grid

blueberry15:03:27

in neanderthal + fluokitten, it would be something like (fmap / grid), if grid is a matrix

bronsa15:03:38

I'd rather write that as (for [row grid] (for [cell row] (/ 1 cell)))

josh.freckleton16:03:51

@donaldball: interesting, is update-cells a standard function? I can't find reference to it. @bronsa: ah, that's true. That looks a little cleaner too.

donaldball16:03:59

No, just seems like a higher-order fn you’d probably want in your domain

josh.freckleton16:03:11

sure, that's a good call too

ccann20:03:06

anyone have tips on using spy from timbre with the threading macros

ccann20:03:43

I want to log the intermediate steps in my -> call

ccann20:03:59

but I want to apply an arbitrary function to each step

ccann20:03:36

(-> messages (spy count) (some-func))

ccann20:03:51

something like that, where I can count the messages and log it before the next step

ccann20:03:18

but not pass the result of (count messages) to (some-func)

jr20:03:52

you can write your own spy function that does that:

(defn spy [val func] (doto val #(println (func %))))

ccann20:03:40

sure yeah, that’s a fair point, but i was hoping to use timbre/spy

jr20:03:10

I would write a small wrapper that invokes doto with timbre/spy and the desired function

ccann20:03:48

I guess in general I’m wondering how people deal with the fact that threading macros sort of discourage logging of the intermediate steps without a little extra work or refactoring them into a let block

ccann20:03:52

thanks jr!

jr20:03:08

threading macro encourages the composition of pure functions so it’s a bit weird for logging to occur between those steps

ccann20:03:27

why is it weird?

ccann20:03:37

Seeing the results of those intermediate representations is useful in my case

stuartsierra20:03:51

I often write little helper functions like spy during development.

stuartsierra20:03:03

Then remove them when I'm satisfied with the result.

ccann20:03:09

maybe I’ll do a feature request to timbre

smw20:03:30

This might be relevant to your interests?

ccann20:03:38

nailed it!

ccann20:03:40

thank you!

ccann20:03:23

ah, well sorta… if only it supported something like #spy/d ^{:fn count}

smw21:03:17

(-> messages (#spy/d count) (some-func))

smw21:03:29

Doesn’t that work?

ccann22:03:27

(-> (range 10) (#spy/d count) (first))

ccann22:03:39

IllegalArgumentException Don't know how to create ISeq from: java.lang.Integer clojure.lang.RT.seqFrom (RT.java:528)

smw22:03:10

(-> (range 10) (count) (first))

IllegalArgumentException Don't know how to create ISeq from: java.lang.Integer  clojure.lang.RT.seqFrom (RT.java:528)

smw22:03:24

not related to #spy/d?

smw22:03:43

user=> (-> (range 10) (#spy/d count) (first))

IllegalArgumentException Don't know how to create ISeq from: java.lang.Integer  clojure.lang.RT.seqFrom (RT.java:528)
user$eval20471.invoke(form-init4724596131896001508.clj:1) count =>
  #object[clojure.core$count 0x688a74b "[email protected]"]

smw22:03:52

on the other hand, it does happily print the fact that it’s a function

smw22:03:43

user=> (-> #spy/d (range 10) (first))
user$eval20484.invoke(form-init4724596131896001508.clj:1) (range 10) => (0 1 2 3 4 5 6 7 8 9)
0

smw22:03:32

user=> (->> (range 10) #spy/d (filter even?) (last))
user$eval20519.invoke(form-init4724596131896001508.clj:1) (filter even?) =>
  #object[clojure.core$filter$fn__4576 0x639ca7c8 "[email protected]"]
9

smw22:03:07

That, however, doesn’t do what you want, and also it somehow modifies the results?

smw22:03:18

user=> (->> (range 10) (filter even?) (last))
8

smw22:03:49

I think I’m over my head here. I guess I need to go read definitions of threading macros to understand if it’s even possible to make it work simple_smile

seancorfield23:03:35

I tend to just do (defn debug [x msg] (println msg x) x) and then (-> (range 10) count (debug "count") first)

seancorfield23:03:59

and have a debug-l version with the args switched for use in ->> expressions.

seancorfield23:03:25

(->> (range 10) (filter even?) (debug-l "after filter even?") last)