Fork me on GitHub
#clojure
<
2015-06-19
>
danielcompton02:06:34

Is there a way to get a seq of what clojure.walk is walking?

leonardoborges02:06:39

@txus: don't mention it! simple_smile I'm glad you found them useful

bmay03:06:41

has anyone here used the twitter-api library?

borkdude07:06:33

@bmay: I've used it

wagjo07:06:56

@bmay for Twitter's streaming API, I think there's nothing better than https://github.com/twitter/hbc

martinklepsch09:06:03

Appending a single element to a seq generated by for — is there a better way than:

(conj (vec (for …)))
concat came to mind but then I need to make the single element a seq first.

andrewmcveigh09:06:45

@martinklepsch: I think concat is the only way to keep lazyness.

martinklepsch09:06:07

don’t care about laziness in this case actually

jprudent09:06:39

@zoldar: event sourcing is really straightforward in Clojure. Not sure it's pertinent to be tied to a library for implementing es.

andrewmcveigh09:06:55

@martinklepsch: I don’t think there’s another way.

zoldar09:06:00

@jprudent: I guess, but still, if somebody put in the effort, why reinvent it. There probably are many corner cases I would have to cover when doing this myself - especially in the part responsible for persisting to event store.

martinklepsch09:06:44

@andrewmcveigh: that’s an equally valid answer ;D

andrewmcveigh09:06:44

I’d usually use (concat .. [thing]), I guess as a habit.

martinklepsch09:06:28

@andrewmcveigh: I guess I’d usually do that to but in this case it’s hiccup ...

martinklepsch09:06:59

(which would still work but may look confusing)

andrewmcveigh09:06:29

Ah, fair enough. Probably best to keep the vectors then.

andrewmcveigh09:06:56

Unless you can rewrite the for with mapv

martinklepsch09:06:33

I could but I don’t think it’d make my eyes any happier

andrewmcveigh09:06:29

maybe a forv macro 😈

martinklepsch09:06:52

haha yeah, I was actually thinking about that 😄

acron10:06:46

Is there a more concise way to do this?

martinklepsch10:06:58

@acron: (defn vhm [c] (into {} (remove #(nil? (second %)) c)))

acron10:06:16

:thumbsup: thanks

martinklepsch10:06:48

also: (defn vhm [c] (into {} (remove (fn [[k v]] (nil? v)) c)))

ambrosebs10:06:24

challenge: make clojure.core/sort return null

martinklepsch10:06:36

@ambrosebs: is that possible at all?

ambrosebs10:06:17

my hypothesis is if the collection changes size to 0 as we go down the then branch it can return null

ambrosebs10:06:49

I'm not snazzy enough with concurrency to figure out an impl

martinklepsch10:06:15

haha, so you’d need “to pull the carpet from under it”

jcf11:06:50

@martinklepsch: comp can shrink down the predicate in remove a bit:

(defn vhm [c] (into {} (remove (comp nil? val) c)))
simple_smile

jcf11:06:13

Pretty sure Medley has a transient version somewhere too if you don’t mind the dependency.

jcf11:06:54

There's remove-vals, which uses transients internally.

(defn- reduce-map [f coll]
  (if (editable? coll)
    (persistent! (reduce-kv (f assoc!) (transient (empty coll)) coll))
    (reduce-kv (f assoc) (empty coll) coll)))
https://github.com/weavejester/medley/blob/master/src/medley/core.cljx#L105-L109

rickmoynihan11:06:05

@martinklepsch: could always do (lazy-cat (for [i (range 10)] i) [:foo])

stian11:06:49

Anyone tried using AWS Lambda from clojure, using their new Java support? Doable without too much friction?

martinklepsch11:06:40

@ragge is the author and has been chatting about it with others here.

stian11:06:54

martinklepsch: Ooh, thank you simple_smile

stian12:06:23

Didn't realize anyone already had made a library, awesome simple_smile

ragge12:06:35

@stian: happy to chat about it if you have any qs

stian12:06:01

@ragge: Cool, will give it a try and let you know if I run into anything.

borkdude15:06:47

How to make clojure.core/sort return nil: http://sprunge.us/VIFc?clj

wiruzx15:06:11

:thumbsup:

martinklepsch15:06:20

So I’m using a Pegdown wrapper in Clojure and get "Error: <aside> is not recognized!” — same fore <figure> & <figcaption>. Any suggestions for getting those tags to work? It’s just HTML rihgt?

Lambda/Sierra15:06:18

Call for tests! tools.namespace reader conditional support in 0.2.11-SNAPSHOT.

Lambda/Sierra15:06:31

Get it like this:

:dependencies [[org.clojure/clojure "1.7.0-RC2"]
                 [org.clojure/tools.namespace "0.2.11-SNAPSHOT"]]
  :repositories [["sonatype-oss-public"
                  ""]]

martinklepsch16:06:40

@stuartsierra: that’s great thanks!

Alex Miller (Clojure team)16:06:27

technically this is more support as I caught most of it in 0.2.10

Alex Miller (Clojure team)16:06:58

I guess 0.2.10 added support for .cljc, and this adds support for reader conditionals in the ns macro

martinklepsch16:06:54

yes, this is exactly what I was waiting for simple_smile

martinklepsch16:06:09

I was also initially confused how I got it basically working with 0.2.10 (given the snapshot adds support)

tcrayford16:06:50

@stuartsierra: I don't use reader conditionals, but I don't detect any noticeable slowdown with 0.2.11 vs 0.2.10 or 0.2.9 (15.62s to refresh-all as measured by criterium against Yeller's ~15k lines of code). Just in case that matters at all (it does to me - the time taken for reload dominates nearly everything else in my inner development loop)

martinklepsch16:06:18

@stuartsierra: hm. getting an exception that seems totally unrelated with the snapshot that I didn’t get with 0.2.10.

Lambda/Sierra16:06:24

It doesn't force the :clj feature, but since it only runs under Clojure(JVM) anyway I assume that's unnecessary.

martinklepsch16:06:29

@stuartsierra: I use it within a boot task and I think something inbetween might be breaking things, will gist the stacktrace in a sec.

martinklepsch16:06:34

uhh, weird. now it’s gone 😄

martinklepsch16:06:04

I’m actually just using ns-tracker really which seems to now correctly report changed namespaces with reader conditionals in their ns form.

Lambda/Sierra16:06:30

tcrayford: yikes, 15K lines in one reload.

tcrayford16:06:40

@stuartsierra: ~2 year old app, only one dev, never felt enough pain to bother splitting it up across projects or whatever.

tcrayford16:06:59

(it's fine, AOT compilation on CircleCI takes ~4 minutes)

tcrayford16:06:07

shoutout too the clojure compiler

martinklepsch16:06:14

@stuartsierra: whats the timeframe to get this cut as a release?

martinklepsch16:06:26

So with sbt is there an equivalent to lein install that installs the thing into my local maven repo?

ragge16:06:41

@tcrayford: is that AOT compilation on linux? can I tempt you to try [ragge/clojure "1.7.0-clj703-SNAPSHOT"] if you dare, that's RC1 with this patch applied: http://dev.clojure.org/jira/browse/CLJ-703

ragge16:06:05

@tcrayford: thankyou, really interested to hear impact on real codebases...

tcrayford16:06:43

@ragge: CI time for circle is very variable. First run took 2:55, but I had a run last night that took 3:05 (without that patch), and times vary between about 3 and 4 minutes. The joys of cloud computing

tcrayford16:06:54

(first run with your patch in that is)

ragge16:06:46

@tcrayford: yeah, maybe not best environment to test in... do you develop on linux, if so you can give this a go: https://github.com/ragnard/clj-703

tcrayford16:06:19

@ragge: nope, no linux dev box here 😞

ragge16:06:52

@tcrayford: ok, thanks anyway... have been trying to collect some data for that patch to show real-world impact

Alex Miller (Clojure team)16:06:39

@ragge: I've pre-screened that ticket for 1.8 so I don't know that any additional data is needed at this point, just awaits the initial look at 1.8 tickets

ragge17:06:48

@alexmiller: oh, great to hear

aengelberg17:06:37

@ragge FWIW I'm running your script on my Ubuntu machine.

aengelberg17:06:45

Will post results once it finishes

ragge17:06:10

@aengelberg: ah, cheers... it's nice to know that it's not just a "my machine" problem... the data I've received so far only includes two other linux reports, but they both show a improvement similar to what I see

aengelberg17:06:21

> 10x speed boost so far.

aengelberg17:06:39

meant to say > 10x speed boost

aengelberg17:06:15

RC1,incanter.core,98453
RC1+CLJ-703,incanter.core,5295
RC1,incanter.core,100599
RC1+CLJ-703,incanter.core,4537
RC1,incanter.core,96687
RC1+CLJ-703,incanter.core,4701
RC1,incanter.core,100557
RC1+CLJ-703,incanter.core,5203
RC1,aleph.http,76473
RC1+CLJ-703,aleph.http,5400
RC1,aleph.http,80024
RC1+CLJ-703,aleph.http,5688
RC1,aleph.http,76575
RC1+CLJ-703,aleph.http,5793
RC1,aleph.http,79155
RC1+CLJ-703,aleph.http,5691
(I submitted to the google form as well)

ragge17:06:58

oh wow... that's a much bigger difference than what I'm seeing... makes me wonder if the test is bad simple_smile

tcrayford17:06:44

@aengelberg: is your drive especially slow?

aengelberg17:06:56

My computer is... special.

tcrayford17:06:07

aren't they all 😉

aengelberg17:06:32

More likely a problem on my machine than with your tests, that's all I'm sayin

ragge17:06:00

ok, thanks for taking the time to run that

seancorfield17:06:32

Style question… should a predicate named with a ? suffix return strictly boolean, i.e., only true or false? Or is a looser truthy / falsey value considered acceptable.

seancorfield17:06:10

The community style guide https://github.com/bbatsov/clojure-style-guide says "The names of predicate methods (methods that return a boolean value) should end in a question mark"

seancorfield17:06:02

And when I asked on the mailing list in 2014 https://groups.google.com/forum/#!searchin/clojure/question$20mark$20boolean/clojure/y8ySWiLXGQc/E8VhX5-CN2cJ there seemed to be a consensus of ? => strictly boolean but it was a relatively small response sample, given the size of our community.

Alex Miller (Clojure team)17:06:24

I think true/false is recommended

Lambda/Sierra17:06:33

@martinklepsch: Will release today if enough people look at it and convince me it's correct.

Lambda/Sierra17:06:02

@seancorfield: I usually coerce foo? functions to boolean

fhanreich17:06:08

@stuartsierra: at all times? even foo? is used somewhere in a private helper function as in (if (foo?..) ), (when (foo?... )), when truthy/falsey is sufficient as foo?'s return value? or do we have a naming convention for a function which returns truthy/falsey?

Lambda/Sierra17:06:36

@fhanreich: Not all the time. But usually.

fhanreich17:06:22

@stuartsierra: Thank you simple_smile I'm guessing no naming convention for my latter question?

Lambda/Sierra17:06:02

@fhanreich: Not really. If it's a function to get a "foo" out of something else, or nil if there isn't a "foo" to get, I just name it foo.

bmay18:06:38

if i want to include a java package (hbc - twitter client) in a lein project, do i have to build the package with maven first?

micah18:06:32

In Clojure 1.7, is there a Var to determine the current platform at runtime?

markstang18:06:29

@bmay: Not if it is available in a maven repository that your project is searching. I don’t know if lein searches other than clojars by default. You can probably specify an additional repository. Or you can download it and “mvn clean install” and then it will be available locally.

arrdem18:06:12

@micah: not that I know of, but you could hack it yourself by having a flag def using reader conditionals

arrdem18:06:29

@micah: do you know what the value of *clojure-version* is?

micah18:06:34

@arrdem I've already got a hack that looks for cljs.analyzer... but I was hoping for something more elegant. I recall discussion saying that such a var would exist.

Alex Miller (Clojure team)18:06:24

clojure-version has existed for a long time

Alex Miller (Clojure team)18:06:56

are you talking about clj vs cljs?

arrdem18:06:10

that seems to be the desire

micah18:06:33

yeah... clj vs cljs

Alex Miller (Clojure team)18:06:58

but we weren't planning on doing anything about it for 1.7

arrdem18:06:33

(def platform #?(:cljs :cljs :clj :clj :default :unknown))

Alex Miller (Clojure team)18:06:56

there is nothing definitive like that right now, but certainly many ways to infer it

micah18:06:01

@alexmiller: Yup.. That's what I was looking for

micah18:06:39

@arrdem: I'm not sure that will work for macros

Alex Miller (Clojure team)18:06:54

yeah, that's where it gets tricky

micah18:06:06

@alexmiller: Ok. I commented on the jira issue expressing my desire for the feature in 1.7.

micah18:06:11

any chance it'll get in?

Alex Miller (Clojure team)18:06:34

low. I am really hoping that RC2==1.7

micah18:06:24

Am upgrading Speclj to 1.7 RC2... I'll have to leave the hack then.

Alex Miller (Clojure team)18:06:48

why don't you just use reader conditionals?

micah18:06:12

well... I tried... but they didn't work.

Alex Miller (Clojure team)18:06:41

(you know that thing where you keep asking "why?"... :)

micah18:06:48

My impression was that during macro expansion, the reader conditionals are always resolving to :clj

micah18:06:36

got lots of errors indicating that

Alex Miller (Clojure team)18:06:54

ok, so specifically macros you're trying to use in both clj and cljs?

bmay18:06:14

@markstang: thanks. looks like if i include the two artifacts with jars it works fine, but there is another artifact without a jar (http://search.maven.org/#search%7Cga%7C1%7Ccom.twitter.hbc) - any idea why?

Alex Miller (Clojure team)18:06:20

@micah: what I'm trying to tease is out is if there's a more important problem to solve. Luke was trying to do the same thing when he filed that ticket.

markstang18:06:58

@bmay: Sorry, not familiar with the package. I would look around and see what they recommend for an implementation.

micah18:06:50

@alexmiller: I've been wondering the same. But this code is all about the macros. I could duplicate the macros for each platform... but yuk.

ambrosebs18:06:11

ragge: seems to shave off a few seconds on core.typed loading. Does your patch made normal loading faster?

ragge18:06:32

@ambrosebs: no, it's only when writing classfiles to disk

dnolen18:06:43

@micah: if the macros are different then they’re different, it’s work that has to be done

dnolen18:06:07

@micah: if they aren’t different then just move them into a file where they can be loaded easily by both Clojure and ClojureScript

ambrosebs18:06:00

ragge: oh so I should bench AOT compiling?

ragge18:06:31

@ambrosebs: is core.typed doing any compile calls?

micah19:06:09

@dnolen: they are only slightly different. The macros are currently easily available for both Clojure and ClojureScript.

ambrosebs19:06:18

the maven build did generate AOT files, not atm

dnolen19:06:34

@micah use namespaces to control that

dnolen19:06:49

i.e move the ones that slightly different into different nses

micah19:06:21

The slight differences are like 1 line in a 20 line macro

micah19:06:53

exception handling in most cases

micah19:06:27

@alexmiller: do you recall Luke's situation? Did he find a better solution?

Alex Miller (Clojure team)19:06:50

I'm not sure in some of this why they're even macros and not functions

micah19:06:07

They throw exceptions. And if they were fns, the line numbers would be all wrong. The exceptions need come from the spec that made the assertion.

luke19:06:37

As a workaround, there are ways to detect, during execution of a macro, if I was called from CLJS.

luke19:06:51

I'm trying to think on the exact technique I used - I ended up not using that code so I don't have it any more.

micah19:06:52

(find-ns 'cljs.analyzer) that's the hack I'm currently using

luke19:06:14

Yep. That's pretty much what you've got to do

micah19:06:20

Seems to me, the root of the issue is: Should macro code know the platform for which it is being expanded? Due to the incompatibilities between platforms, I think the answer has to be 'yes'.

Alex Miller (Clojure team)19:06:10

micah: I have no answer for you at the moment but I will re-raise this with Rich before we release 1.7 and we may do something

Alex Miller (Clojure team)19:06:31

and I apologize for conflating reader conditionals with this. the problem here is really in generating (writing) code with macros, so it is not something reader conditionals help with. macro files are always read as Clojure code.

Lambda/Sierra19:06:02

tools.namespace 0.2.11 release is cooking…

micah19:06:06

@alexmiller: Sounds like a plan. No worries. And thanks for all your help today. You're awesome!

bmay20:06:20

does clojure have access to java guava libraries?

gtrak20:06:00

@bmay: it can use them via java interop, but you'll have to be more specific about your use-case.

bmay20:06:17

trying to access Lists right now

gtrak20:06:02

should work fine

gtrak20:06:22

(com.google.common.collect.Lists/newArrayList [1 2 3]) works for me

gtrak20:06:29

but why would you want to do this?

gtrak20:06:30

afaik there isn't a third-party library that relies on guava's concrete lists, and clojure has its own, so you could just use those.

bmay20:06:52

hmmm that does not work for me

bmay20:06:23

trying to mimic this java for hbc: List<Long> followings = Lists.newArrayList(1234L, 566788L);

gtrak20:06:35

java varargs are arrays, the compiler is stuffing those into an array for you. You'll have to do it manually in clojure with into-array to meet this signature: public static <E> ArrayList<E> newArrayList(E... elements)

gtrak20:06:53

when I wrote it, I was calling the iterable version by passing it a clojure vector

gtrak20:06:13

also, imo, there's no reason to use newArrayList if you have java7 and can use the diamond operator.

gtrak20:06:52

ImmutableList.of(arg1,arg2,arg3) is kind of nice, but i'd just use clojure's from clojure.

bmay20:06:10

wow okay. this is a new world to me haha

bmay20:06:35

by varargs you mean you can supply any number of E into the newArrayList method?

gtrak20:06:56

yea, that's what the '...' means

gtrak20:06:28

but it's a compile-time trick

bmay20:06:37

so youre saying i can likely just use a clojure array in place of newArrayList()?

gtrak20:06:20

clojure vectors and sequences implement java.util.List and Iterable

bmay20:06:26

yup okay. looks like it just called Joiner.join later on which takes an iterable

gtrak20:06:25

also we have alternatives to Joiner simple_smile, interpose, interleave, clojure.string/join

gtrak20:06:42

apply str

bmay20:06:16

yeah, im just looking at the code for hbc (java twitter client)

bmay20:06:30

thank you though

andrew23:06:46

has anyone put together something like clojure koans where the student needs to figure out what part of clojure would be most suitable given a description or a snippet of code? ... like "in this situation a defrecord would be better than deftype" ... and "in that situation you should use a vector instead of a list" ... and maybe the student proceeds with a choice and further down the road discovers and understands the pain if their choice was suboptimal .... ?

johnmendonca23:06:32

@andrew: it is not for idiomatic clojure specifically, but I like http://exercism.io as you can view and discuss others' approaches for the given problems