Clojurians
#clojure
<
2016-01-22
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

didibus00:01:11

Is there a function like map, but where I can discard some elements? A kind of combined remove+map where I would remove elements I don't need, and transform the ones I do at the same time?

bfabry00:01:23

@didibus: you could do that using reduce. it would be cleaner to just compose remove and map though

didibus00:01:52

@bfabry: If I compose remove and map, it'll loop twice though. But on #C03S1KBA2 irc I was told about the keep

didibus00:01:22

Which does exactly what I want

bfabry00:01:20

@didibus: if you compose them as transducers it won't :wink: alternatively, the reduce version (reduce #(if (odd? %2) (conj %1 (inc %2)) %1) [] [1 2 3 4 5])

meow00:01:41

transducers are the :love_hotel: for functions

didibus00:01:40

Hum, I hadn't really paid attentions to transducers. Pretty cool though, I was actually wondering how to do that in Clojure

bfabry00:01:03

@didibus: transducers form user=> (into [] (comp (map inc) (filter odd?)) [1 2 3 4 5 6 7 8]) ;; assuming you want the result in a vector

didibus00:01:10

Do reducers also compose like that?

bfabry00:01:43

never used reducers sorry

bfabry00:01:18

actually my transducer form was round the wrong way in comp, should be (into [] (comp (filter odd?) (map inc)) [1 2 3 4 5 6 7 8])

bfabry00:01:25

filter, then map

didibus00:01:14

guess it depends if you want to remove the odd ones after the increment or before

meow01:01:00

into with tranducers is super handy - use it all the time

seancorfield02:01:07

Well, we have Clojure 1.8.0 live in production on three of our five servers. New Relic’s epic fail this afternoon called a halt to our rolling upgrade.

seancorfield02:01:23

First time we’ve direct linked our entire code base!

krchia02:01:20

hi, i’m running into some problems using migratus

slackbot02:01:21

Yo it's clojurian, whats up ?

krchia02:01:19

if i use the current version from the luminus template versus an older version from a tutorial (clojure web development essentials)

krchia02:01:33

i run into some kind of problem with SLF4J

krchia02:01:13

adding the slf4j dependency inside the luminus template still gives me the error

krchia02:01:27

the older version works fine though

seancorfield03:01:10

Using Leiningen? If so, try lein deps :tree and see if it identifies the conflict in versions for you.

seancorfield03:01:06

Java library versions can be a bit of a pain point since it’s hard to tell when they’ve introduced incompatible changes a lot of time :frowning:

krchia03:01:35

i tried lein deps :tree, but i can’t find the problematic library listed in the output

bcoop71304:01:43

any suggestions on getting a backend websocket server going? looking for more of a small library than a http://socket.io equivalent.

bja04:01:04

why might a BufferedImage's .getHeight() be underreporting the height by roughly 37 pixels?

flyboarder04:01:33

I have a ring app serving some css and png files, the css load on my page fine but the images will not load… says not found?

nowprovision04:01:43

@flyboarder what is your static ring handler setup like?

nowprovision04:01:20

possible related if pngs are referenced from css files remember the png path is then relative to the css path not the root /

flyboarder04:01:02

@nowprovision: i dont know what you mean by relative to css not root / ??

nowprovision04:01:20

are the png references in the html

nowprovision04:01:23

or in the css files?

nowprovision04:01:35

what does your ring handler setup look like?

nowprovision04:01:51

try changing to route/files unless your intent is a single war at the end

flyboarder05:01:18

@nowprovision: haha that seems to have stopped serving all the static files :stuck_out_tongue:

nowprovision05:01:34

change root-path to "resources/"

nowprovision05:01:32

(route/files "/" { :root "resources/" } ) or (route/files "/" { :root "resources/public" } )

flyboarder06:01:55

using files still resulted in no assets served, resources correctly serves css via html but not images

bradford06:01:50

Is it possible for me to have parallel operations inside a doseq? doing some stuff with side-effects, but here's a hackeneyed example:

(defn wat []
  (let [a (range 2)
        b (range 2 4)]
    (doseq [x a
            y b]
      (prn (str x " " y)))))
expected outcome:
0 2 
1 3

bradford06:01:25

but instead I get

0 2 \ 0 3 \ 1 2  \ 1 3

bradford06:01:40

Which I understand why. Just not sure how to get what I need.

dmitrig0106:01:51

there may be a more idiomatic way of doing this, but i've used something like

(let [a (range 2)
        b (range 2 4)]
    (doseq [[x y] (map vector a b)]
      (prn (str x " " y))))

dmitrig0106:01:40

@bradford: ^

dmitrig0106:01:28

you can of course also use map+doall as an alternative to doseq, which might be better since it's mapping anyway

dmitrig0106:01:32

i.e.

(let [a (range 2)
      b (range 2 4)]
  (doall (map (fn [x y] (prn (str x " " y))) a b)))

bradford06:01:02

Ahh. Let me try that...

bradford06:01:23

@dmitrig01: Yes, it worked :simple_smile: thanks!

seancorfield06:01:27

How about (doseq [[x y] (zipmap (range 2) (range 2 4))] (prn x y))?

seancorfield06:01:16

Since you're printing, you really want the side effects, not the result, so you don't really want (doall (map ...))

dmitrig0107:01:45

yea, zipmap very similar to map vector

kenrestivo08:01:03

mapv i think is eager

samlinncon09:01:34

having trouble with my log in function.anyone who can help?

samlinncon09:01:16

am new to clojure trying to learn making my own web application

jethroksy10:01:15

@samlinncon are you using a library?

jethroksy10:01:38

Buddy or friend are good auth libraries

samlinncon10:01:49

no am not using any library,just a query to the database

jethroksy10:01:09

Paste the snippet here?

samlinncon10:01:39

(defn login "function used to authenticate users in the system" [id username password role] ;;validate form (cond (empty? username) (layout/render "login.html" {:msg "Please Enter a username"}) (empty? password) (layout/render "login.html" {:msg "please enter a password"}) (empty? role) (layout/render "login.html" {:msg "please select a role"}) (not (seq (db/get-userinfo-by-username username))) (layout/render "login.html" {:msg "Username does not exist"}) (not (crypt/compare password (:password (first (db/get-userinfo-by-username username))))) (layout/render "login.html" {:msg "Incorrect Password"}) :else (let [user-data (first (db/get-userinfo-by-username username)) id (:user_id user-data) role user-data] ;;set the session data (println ":::" username role) (println "###" util/set-session-data!) ;;(util/set-session-data! id username password role ) (cond (= role "admin" ) (layout/render "admin/admin.html") (= role "secretary" ) (resp/redirect "secretary/secdashboard.html")))))

jethroksy10:01:34

What's your error

samlinncon10:01:58

page not found

samlinncon10:01:07

login post url

cl0jurian10:01:49

@samlinncon show your routes.

samlinncon10:01:21

(defroutes home-routes (GET "/" [] (login-page)) (GET "/reset" [] (reset-password-page)) (GET "/about" [] (about-page)) (POST "/login" [ id Username password role :as req](println ":)" req) (login id Username password role)))

jonahbenton11:01:28

hey @samlinncon what does your form action say?

nxqd12:01:00

@nberger: thanks :smile:

jjttjj15:01:38

Any particular reason i shouldn't use (. clojure.lang.RT (nextID)) (stolen from the gensym source) to generate an int that's unique throughout the running app? I'm wrapping a java library which has methods which require a unique id be passed to it on each call.

jjttjj15:01:42

there are several "types" of ids which must be tracked and that would be much easier of a solution than figuring out where to put a bunch of incrementing atoms

bronsa15:01:47

@jjttjj: RT/nextID is an implementation detail

bronsa15:01:11

it's not supposed to be public API

jjttjj15:01:54

@bronsa: yeah i kinda figured. thanks!

bronsa15:01:27

@jjttjj: as a rule of thumb, don't rely on anything from the java sources of clojure except for the clojure.lang public interfaces and clojure.java.api.Clojure,

jaen16:01:27

@bronsa: so using MultiFn directly instead of through defmulti and defmethod is okay by that rule?

bronsa16:01:25

@jaen: I said interfaces

meow16:01:26

@jjttjj: could you just use a stateful function?

jaen16:01:19

@bronsa: right, you did. And it's a class. And I see no interface exposing adding methods. Kinda sad, since I was using it as a dispatcher in a component and it worked well so far.

bronsa16:01:47

I'm not quite sure why you'd need to user MultiFn directly

jjttjj16:01:21

@meow: what do you mean by that? Google's not particularly helping.

meow16:01:53

(defn gen
  "Returns a function that, when called, will call f with an incremented
   generation number and an additional context data argument."
  [f]
  (let [generation (volatile! (long -1))]
    (fn
      [data]
      (vswap! generation #(inc (long %)))
      (f @generation data))))

meow16:01:58

for example

jaen16:01:59

@bronsa: So I wanted to dispatch on handlers registered by dependent component. Hence I need to register multimethods at system boot time and I potentially might have more than one instance of a component, then I can't use a global variable multimethod, since components could potentially clobber the handlers. So I figured a multimethod not bound to a var, but used as a component record field would make sense.

jaen16:01:19

Maybe that's dumb, but that was my first idea.

bronsa16:01:55

it's a pity that clojure.core/add-method is not a thing, I agree

jaen16:01:14

Yup, would be nice to have a def-less version of defmethod & defmulti.

bronsa16:01:35

@jaen: open a ticket in JIRA :simple_smile:

jaen16:01:27

Sure, I can do it over the weekend.

bronsa16:01:08

the patch should be very simple aswell

kul16:01:41

hi vim users, are you able to get java classes auto completion hints using vim fireplace?

kul16:01:26

I remember having this some time back but i am not getting any completions with my current setup

juhoteperi16:01:30

@kul: Yes. At least with cider-nrepl.

kul16:01:52

wtf please share you .profiles.clj

kul16:01:00

i am having 0.10.1 still not working

juhoteperi16:01:29

What are you trying to autocomplete and in what context?

kul16:01:45

e.g. System/<Ctrl-X-O>

kul16:01:54

does not suggest anything for me

juhoteperi16:01:15

Works for me. And have you loaded the ns?

kul16:01:40

yes it loaded

jjttjj16:01:13

@meow: is doing something like this better than just having a top level atom that i keep inc-ing?

(defn gen
  []
  (let [generation (volatile! (long -1))]
    (fn
      []
      (vswap! generation #(inc (long %))))))

(def next-id (gen))
(next-id)
Or is this abusing it and the gen function should strictly be intended to wrap another function?

juhoteperi16:01:14

And triggerin autocomplete shold anyway load the ns if it's not loaded

kul16:01:40

Are you using salve.vim for bringing up console?

juhoteperi16:01:06

Nope, I run repl on separate terminal

kul16:01:02

Still not working

kul16:01:32

what could i be doing wrong! Java hints are more crucial than clojure imo

meow16:01:37

@jjttjj: I don't like poluting my namespace with top-level atoms

meow16:01:56

that code I posted was just an example - you could further modify it to suit your needs better

meow16:01:36

look at the source code for clojure core to see how it uses volatiles

jjttjj16:01:29

pkobrien: thanks again

jonahbenton17:01:49

hey @jaen fwiw, defmethod is just sugar on (.addMethod multiFn): https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L1669 and defmulti similarly is just doing (new MultiFn).

jaen17:01:58

@jonahbenton: yes, I did figure that out and it's exactly what I'm doing right now, but while defmethod can be basically used as-is with a free-standing MultiFn (although the def in the name is slightly misleading), defmulti has no such non-`def` alternative and I my question was in light of what bronsa said about relying on implementation details - basically if it's kosher to rely on such implementation details.

bronsa17:01:01

@jonahbenton: problem is that being macros you can dynamically add methods or define multimethods at runtime

kul17:01:54

This is embarrassing, i had ~/.lein/profile.clj

kul17:01:41

oh the bright side i came to know about ultra from @juhoteperi 's dotfile

kul17:01:20

ultra is cool! kudos to the author

jonahbenton17:01:11

@jaen depends on what you mean by rely. :simple_smile: If you're making a lib, yeah, probably bad idea without requisite disclaimers. If you're making an app, well- your source code may not be forward compatible with later versions of clojure, and you can check that at startup- if (new MultiFn) fails, you exit. A packaged app would continue to work, modulo maintenance concerns on this specific architectural decision.

jaen17:01:01

Well, I'm hoping for it to be a lib at some point, so yeah, better to avoid it. So nice to hear a patch to expose that in clojure.core is welcome.

jaen17:01:16

(it's basically an event handling component for event sourcing that gathers all domain events from it's dependencies)

jonahbenton17:01:49

@jaen gotcha, you're basically talking about dispatch on event type

jaen17:01:15

Yup; I just figured I could use something that Clojure already has instead of rolling my own.

jonahbenton17:01:48

know about core.match?

jaen17:01:48

Sure I do, my first exposure to FP was Haskell, so it's one of the first libraries I add to any project ; d

jaen17:01:58

But that doesn't help - it's not extensible from the outside.

jaen17:01:10

Multimethods are.

jonahbenton17:01:55

yup, gotcha. runtime defined dynamic predicate dispatch

jaen17:01:54

Yup. I could probably just shove all handlers into a map and call it a day, but I figured MultiFn is probably more optimised than that ; d

alexmiller17:01:22

protocols are fairly amenable to this kind of programmatic construction

alexmiller17:01:43

but of course limited to selection based on type

alexmiller17:01:15

protocols are essentially defined as a big map of fns

jaen17:01:43

I need [event-type event-version] at least, so protocols could become an awkward visitor pattern

jonahbenton17:01:23

@jaen are your events derived from parsing a data steam?

jonahbenton17:01:12

@alexmiller: thanks- would you agree that direct use of MultiFn- create new, .addMethod, etc- would be undesirable in a library?

alexmiller17:01:41

I would consider MultiFn to be part of the implementation and subject to change

alexmiller17:01:49

not that we have any plan to change it :)

jonahbenton17:01:25

@alexmiller- thanks, makes sense. Any reason that an add-method doesn't exist in core, or patch for same would not be welcomed?

jonahbenton17:01:02

Can imagine concerns related to lifecycle- what impact would add-method at runtime have on safety. But there is remove-method...

alexmiller17:01:11

not known to me :)

alexmiller17:01:52

sometimes you can find more background by trolling the clojure irc logs around when things were added

alexmiller17:01:41

MultiFn dates back to sept/oct 2007

alexmiller17:01:51

hrm, unfortunately that's pre irc

alexmiller17:01:03

which started in feb 2008

alexmiller17:01:33

looks like there was an earlier PolyFn

jonahbenton17:01:42

gotcha, thanks Alex, that makes sense

alexmiller17:01:13

the intention there seems to be that defmethod is the way you add methods to a multi

alexmiller17:01:47

seems like defmethod body could be split into the var part and the add part though

jonahbenton18:01:29

interesting comparing that commit with https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L1691 vars originally had a dispatch map?

jonahbenton18:01:34

but now, yeah, looks like defmethod could be cleanly split. and I see addMethod uses rwlock around the method table.

sstawecki18:01:10

Hi developers! I'm new in this and I would like to know about the following commands: lein figwheel lein run lein cljsbuild auto I'm a little confused about them because I don't know if "lein figwheel" does the same as lein "cljsbuild auto; lein run"

sstawecki18:01:20

Ouch, I guess I should ask the same in the another channel :face_with_head_bandage:

danburton18:01:13

Not the same. Among other things, lein figwheel gives you a repl that can run code in your browser.

sstawecki18:01:41

So, if I run “lein figwheel” is not necessary to do a "lein cljsbuild auto; lein run” right?

sstawecki18:01:50

Apologies for my ignorance :sweat:

octo22119:01:39

@jaen: core.match ? I'm using it for event dispatch

octo22119:01:18

static but flexible

octo22119:01:47

(although it would be nice to have a dynamic solution)

spieden19:01:25

sstawecki: correct (might be better to ask further cljs qs in #C03S1L9DN)

spieden19:01:34

@sstawecki: ^^

dmitrig0120:01:29

I'm getting a java.net.SocketException "Permission Denied" error when running my ring/jetty server - trying on all different ports, all above 1024, and it it just doesn't seem to want to start – any advice? trying to bind both to 0.0.0.0 and 127.0.0.1, doesn't work either

jonahbenton20:01:06

hey @dmitrig01: try -Djava.net.preferIPv4Stack=true ?

pguillebert20:01:58

argh we still need this kind of hacks in 2016 ? God, IPv6 will never prevail :simple_smile:

agile_geek20:01:45

It's often a symptom of wrongly configured IPv6 or even some tools (like remote desktop, security tools messing up IPv6)

alexmiller20:01:00

I've seen stuff like this where there is an ipv6 localhost in /etc/hosts before an ipv4

lvh20:01:45

Heya! Does anyone have any experience with data streaming libs in Clojure I should take a look at? I know of Storm and Onyx; most of the Hadoop stuff seems to be focused on traditional Hadoop jobs rather than online processing.

bja21:01:33

I would not recommend Storm for new clojure projects unless you either already have a storm infrastructure and experience or you need to take advantage of the multiple language capabilities. It takes a lot to get right, and having used it for awhile, I don't see any compelling advantages of it (outside of multi language) compared to Onyx.

dmitrig0121:01:28

ack - that didn't help. turned out i set up the configuration wrong to the point where the port wasn't even getting passed into jetty, so it was trying to bind to a nonexistant port

pguillebert21:01:48

Onyx looks really cool and seems to aim at being Storm without the quirks

pguillebert21:01:59

I’ve used Storm for a long time, it’s a good tech, but clojure DSL is not great and very seldom used in the community apparently

bja21:01:39

I'll also note that stand alone clojure apps via docker images consuming kafka/sqs solve a lot of my problems given that I've already solved how to deploy random containers and manage my queuing system. You end up writing a small internal library for metrics/logging anyway, and if you can reuse that, deploying a single container or uberjar isn't usually too different from deploying a lot of them.

michaeldrogalis21:01:41

Hello. I can answer questions about Onyx. @lvh

lvh21:01:54

michaeldrogalis: Hiya! I’ve never had an excuse to use Onyx yet but it looks like that might be changing :simple_smile: I’m not sure we can get away with just Onyx, though; we have some stuff that’s online (data enrichment stuff), but a bunch of stuff that’s offline, for which HDFS still seems to be the standard data store. What do you normally store data going out of Onyx in, assuming that at some point Onyx is going to look at it again?

lvh22:01:16

michaeldrogalis: the competing design is just a bunch of HDFS, with spark streaming attempting to do the realtime stuff, which is somewhat of an open question if it can actually do it

lvh22:01:32

also even offline spark stuff just looks a lot grosser than onyx imho

lvh22:01:40

but I want the answer to be clojure so I’m probably biased

michaeldrogalis22:01:42

@lvh Storage choice is heavily dependent on the application, can't generalize that.

michaeldrogalis22:01:21

We're working on better integration points with HDFS, but it's mostly being driven by customer demand. Time is at a premium

lvh22:01:16

michaeldrogalis: Sure, that makese sense :simple_smile: We’re looking at fairly large amounts of data (often includes pcap, netflow, &c), a lot of it sensitive, so being able to run on dedicated hardware is a plus; combine with in-house expertise on running HDFS, and HDFS becomes a clear first candidate

lvh22:01:40

michaeldrogalis: you do do a bunch of “offline” data processing a la classic Hadoop MR with Onyx, though, right? Just not from/to HDFS?

michaeldrogalis22:01:36

@lvh: Yeah, most projects that I've consulted on have used Datomic as a storage target for moving around large-ish blocks of immutable data

lvh22:01:22

michaeldrogalis: gotcha. what backend for datomic?

lvh22:01:48

michaeldrogalis: napkin-mathy we’re looking at >200PB so a few of the simpler options aren’t applicable

bradford22:01:07

Hey, big thanks to everyone for help with my cluster simulator. I’m really close. I’ve figured out pubsub in core.async, and using go blocks to simulate workers. I’ve got the fn for one worker+inputs/outputs. I can’t quite figure out how to build the pubsub channels with the dependency DAG tho. I think I want to do some kind of reduce(?) across a depth-first traversal, chaining the pubsubs together, with the final result being the “head” channels I put the data into. Does that make sense? I’m using Loom. cc @danielcompton :cake: :coffee: :dog:

bradford22:01:12

Oh, and this’ll be OSS :pray::skin-tone-2:

bradford22:01:41

Code if anyone's got wisdom, apologies for the ugly https://gist.github.com/LusciousPear/6b99efc863735aab0d44

karlis23:01:55

I was looking through inner workings of core macros. Curious, what is let* that appears in expanded let?

karlis23:01:10

user=> (macroexpand '(let [x 1] x)) (let* [x 1] x)