Fork me on GitHub
#clojure
<
2015-08-13
>
shamatov09:08:31

@andre.richards: I've already left chat last time when you answered my question about "how to start in clojure", but I got your message and just want to thank you for advise.

escherize09:08:26

Has anyone seen a qr code generator (for clj or java) with the ability to embed a logo into the qr code?

zcaudate10:08:12

and there’s this:

zcaudate10:08:35

which the first one is based off

escherize10:08:11

I guess, what I can do is create a QR code and on top of it draw the logo image of the company

escherize10:08:06

ahh, someone was even nice enough to make this: https://github.com/killme2008/clj.qrgen

escherize10:08:43

by the same guy who wrote defun - the defn + core.matched library.

faust4510:08:09

i trying to optimize my workflow, can any one suggest how i can map stack trace to sources in vim ?

ericnormand15:08:21

I have a leiningen puzzle if anyone can help

ericnormand15:08:35

I know lein deps can install the dependencies locally

ericnormand15:08:44

but it does not seem to install the plugin dependencies

ericnormand15:08:51

is there a way to do that?

ericnormand15:08:20

or even install a jar from clojars with all its dependencies?

swizzard15:08:36

what do you mean ‘plugin dependencies’?

ericnormand15:08:49

@swizzard: I mean the jars required by the plugins

swizzard15:08:17

i guess i should’ve said “what do you mean by ‘plugin’?” instead?

ericnormand15:08:27

we're running the lein-immutant plugin

swizzard15:08:37

like stuff that goes in ~/.lein/profiles.clj?

ericnormand15:08:04

so, specifically, lein immutant war builds the jar, then downloads this stuff

Retrieving org/immutant/wildfly/2.0.0/wildfly-2.0.0.pom from clojars
Retrieving org/clojure/tools.nrepl/0.2.7/tools.nrepl-0.2.7.pom from central
Retrieving org/projectodd/wunderboss/wunderboss-wildfly/0.6.1/wunderboss-wildfly-0.6.1.pom from central
Retrieving org/projectodd/wunderboss/wunderboss-wildfly/0.6.1/wunderboss-wildfly-0.6.1.jar from central
Retrieving org/clojure/tools.nrepl/0.2.7/tools.nrepl-0.2.7.jar from central
Retrieving org/immutant/wildfly/2.0.0/wildfly-2.0.0.jar from clojars
then creates a war

ericnormand15:08:23

and I want that stuff to already be loaded when I do lein deps

ericnormand15:08:30

or some other command that I can do before

ericnormand15:08:41

because we're building docker images

ericnormand15:08:47

and this downloads each time it builds

ericnormand15:08:01

whereas the lein deps line is up above

ericnormand15:08:08

and all of the jars are in the cache

ericnormand15:08:19

so they don't need to be refetched

ericnormand15:08:41

well, I didn't expect there to be an easy answer

ericnormand15:08:45

thanks everyone!

tcrawley15:08:13

ericnormand: the war step resolves those directly, and they aren't visible at lein deps time

ericnormand15:08:45

I'm testing whether I can run lein immutant war right after lein deps

ericnormand15:08:03

@tcrawley: and thanks! you rock

tcrawley15:08:17

but you could add a profile that adds [org.immutant/wildfly "2.0.0"] to :dependencies, and you can then do lein with-profile +war-deps deps

tcrawley15:08:46

and you should also upgrade to 2.0.2 :)

tcrawley15:08:05

all the rest of those deps are transitive from org.immutant/wildfly

tcrawley15:08:24

my pleasure!

ericnormand15:08:24

I'll give that a try

Pablo Fernandez16:08:16

Is there a better way than this (keyword (str (name (:name the-keyword)) "-panel”)) to add -panel to a keyword, so that :home turns into :home-panel.

luxbock16:08:39

@pupeno (keyword (str (name :foobar) "-panel")) right? I can't think of anything shorter

Joe R. Smith16:08:49

(-> :foobar name (str "-panel")) looks a little better

nberger17:08:35

(-> :foobar name (str "-panel")) is more readable, but it's missing a keyword call, and I like to not thread the first call: (-> (name :foobar) (str "-panel") keyword)

swizzard17:08:19

@nberger: any particular reasons why you prefer (-> (a b) c d) over (-> b a c d)?

nberger17:08:56

not sure, but I guess it's because the idea of the threading macro is to unwrap nested calls so they can be read as "transformation steps"... unwrapping the first call gives an additional step for my brain to interpret

nberger17:08:04

this is especially true with short calls like (name :foobar)... if it's a map/reduce/etc with a long (or not so long) fn as first param, I will probably do:

(->> coll
  (map #(some big fn on %))
  (filter some-pred)
  first)

nberger17:08:10

@swizzard: it's sometimes fewer lines too (but not in this case)... it's aesthetics, so it depends

Alex Miller (Clojure team)18:08:32

hello all, just a quick note that the Clojure/conj CFP has been pushed back a week and will now close Aug 21st https://cognitect.wufoo.com/forms/clojureconj-2015-call-for-presentations/ - would love to have submissions re Clojure or ClojureScript use, libraries, experience reports, etc

cddr20:08:08

Does anyone know of a brakeman style security scanner for clojure?

gniquil20:08:52

Does anyone use Ember with Ember Data? Is there something similar to jsonapi-resources for clojure?

mattly21:08:55

is there a way to get the arity of an anonymous function?

bostonaholic21:08:34

@mattly: like this? (fn [& args] (count args))

mattly21:08:27

no, I need it for given a function

mattly21:08:38

(arity fun)

mattly21:08:45

without calling it

arrdem21:08:08

there isn't a good way to do that without serious class introspection.

arrdem21:08:28

hum... lemme give that a shot actually

bostonaholic21:08:36

that will be especially difficult since functions can be overloaded

arrdem21:08:20

hum... none of those are quite right...

arrdem21:08:39

that one I will endorse

arrdem21:08:46

the others are partial solutions at best

mattly21:08:56

except it doesn’t work for anonymous functions

arrdem21:08:16

no the one I linked works on arbitrary lambdas

mattly21:08:21

usually when something is this hard it means I’m doing it wrong 😛

arrdem21:08:24

yes the top answer only works on vars

tel22:08:18

is there a way to write a reduce which operates over vectors and maps the same way?

tel22:08:36

something like

tel22:08:38

(reduce (fn [m [k v]] (assoc m k (f v))) m0 m)

tel22:08:44

works for maps

tel22:08:03

but given the way assoc works it’s very close to working with vectors, too

noisesmith22:08:36

tel: perhaps you want conj

noisesmith22:08:21

(reduce conj m0 m) will work on a vector or a hash-map (and is the simple part of the definition of into)

tel22:08:31

but I’d like to perform that transform f on the inside

arrdem22:08:25

I think that's the definition of the map transducer...

tel22:08:06

that’s probably true

tel22:08:25

or it’s close anyway

tel22:08:34

ignoring reduced values and all that jazz

arrdem22:08:38

It's not quite true because you're describing a function f over either kv pairs or vs

arrdem22:08:53

or at least that's what you seem to be trying to describe

tel22:08:15

yeah, I’d like that to work

tel22:08:30

but you can see it as an indexed visitation or generalized fold

tel22:08:18

I’m working with some things that are very similar to transducers… maybe I should just figure out how to represent them as transducers exactly and steal all that machinery

arrdem22:08:25

I mean you seem to be describing (fn [f] (map (fn [e] (if (map-entry? e) [(first e) (f (second e))] (f e))))

arrdem22:08:43

which I wouldn't characterize as general but shrug

arrdem22:08:04

just because it's coupled to some knowledge of what you'll be mapping over

arrdem22:08:32

I suppose you could define an "updating" function by composing that with into

tel22:08:35

(well in Haskell you’d have this as an Indexed Traversal 😉)

arrdem22:08:53

yeah but we're not there so we have this weirdness 😞

arrdem22:08:17

Lemme take a stab at this I have an idea

tel22:08:18

that might be enough though

tel22:08:28

I think I can get by with just maps and sequences

tel22:08:48

(or rather I can get by without them at all, but I’d like it, ha)

tel22:08:02

oh, well, no… I don’t have the vector indices

arrdem22:08:43

(defn map-entry?
  [e]
  (or (instance? clojure.lang.MapEntry e)
      (and (vector? e) (= 2 (count e)))))

(defn updating [f]
  (fn [col]
      (->> (map (fn [e]
                  (if (map-entry? e)
                    [(first e) (f (second e))]
                    (f e)))
                col)
           (into (empty col)))))

arrdem22:08:50

stupid friggin tabs

tel22:08:56

well, wait, no, I guess I don’t need it with a transducer

tel22:08:40

oh, I forgot about that empty trick

arrdem22:08:41

fixed somewhat

tel22:08:01

let me just throw my real use case out

arrdem22:08:07

yeah so I'm pretty sure that could just be a comp transducer...

tel22:08:16

I’m working with re-frame

tel22:08:38

which wants you to define state transitions in time via reducers

tel22:08:59

(and maybe transducers would work better here, but I’m not yet ready to give up)

tel22:08:15

so we have a bunch of [a s -> s] functions

tel22:08:55

we can sequence them (defn seq [r1 r2] (fn [a s] (r2 e (r1 e s))))

tel22:08:28

or we can run them in parallel

tel22:08:02

(defn par [r1 r2] (fn [a [s1 s2]] [(r1 a s1) (r2 a s2)]))

tel22:08:34

if we generalize the first type to [a i -> o] then these have types [[a i -> x] [a x -> o] -> [a i -> o]] and [[a i1 -> o1] [a i2 -> o2] -> [a [i1 i2] -> [o1 o2]]]

tel22:08:55

which, tbh, isn’t much simpler…

tel22:08:37

seq obviously generalizes to whole lists of reducers all combined in sequence

tel22:08:54

and par obviously generalizes to go “across” whatever collections you like

tel22:08:13

right now I’ve been doing it over a map

tel22:08:21

but it’d be convenient to do it over a sequence too

tel22:08:37

(defn par
  "Produce an action over maps from a map of actions. If an action returns nil
  then it is excluded from the output map. Map keys which have no corresponding
  action are passed through untouched."
  [as]
  (fn [ev m0]
    (persistent!
      (reduce (fn [m e]
                (let [v0 (get m0 k)
                      v1 (f ev v0)]
                  (if v1 (assoc! m k v1) (dissoc! m k))))
              (transient m0) as))))

tel22:08:56

I guess the nil bit confuses the issue a bit

noisesmith23:08:39

arrdem: testing for two element vectors (or even map entry instance) leads to weird corner cases. Why not just be a functor and switch behavior by collection type not element type?

tel23:08:08

be a functor? via an interface or something?

arrdem23:08:09

noisesmith: yeah you could do that too... in my mind this is a mapping that's variant on the type of the elements of the seq being mapped over (the special case being whatever the type of a map pair is, otherwise just the elements). You're right that would behave a lot better.

arrdem23:08:45

because here you have the issue of (updating [[:a :b]]) being operation ambiguous

noisesmith23:08:34

tel: not literally in the haskell sense, just sharing that aspect of dispatching what it does in a way that is appropriate for the collection type - I'm using the term quite loosely

tel23:08:53

how would you do that best in clojure?

noisesmith23:08:03

with a protocol

noisesmith23:08:16

or maybe a multimethod

arrdem23:08:25

protocol to be sure

arrdem23:08:56

unless you want something other than single dispatch

tel23:08:15

is that how you choose it? multi/single dispatch?

ghadi23:08:38

somewhat, there's a spectrum for sure

ghadi23:08:49

multi dispatch has to be a multimethod

arrdem23:08:50

multimethods can express arbitrary open dispatch, but protocols are much more efficient for open single dispatch

ghadi23:08:05

but single dispatch could be either... protocols are great for typeclass like cases

ghadi23:08:37

(In this case you were inspecting that it was a vector and the size of the vector too, in the case that the vector is a mapentry)

tel23:08:53

but you can’t really do typeclasses without a type system and prolog to pipe around your vtables, ha

ghadi23:08:58

but don't mind me, I just jumped in and haven't hit the scrollback

tel23:08:28

thanks for joining 😄

ghadi23:08:57

I don't really want to dig too far into re-frame, but what does "define state transitions in time via reducers" mean?

tel23:08:54

there are a few ways of looking at it… the easiest is just to note that all of the “event emitters” and “dispatchers” and things are doing a lot of inversion of control

tel23:08:01

but at the end of the day

tel23:08:16

your ultimate effect is just a pure function

tel23:08:22

event state -> state

tel23:08:26

if you’ve got a stream of events then (map (fn [e] (fn [s] (reducer e s))) events) is a stream of functions

tel23:08:31

compose them all together

tel23:08:49

and you’ve got a big state -> state transformer

tel23:08:59

or scan over them with application to get a stream of states

tel23:08:08

that’s all the state management you want to be doing

tel23:08:17

then the rest is just decomposing reducers

tel23:08:23

which isn’t too hard

ghadi23:08:27

Thanks for that explanation