#clojure log - Mar 07 2015

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:00 justin_smith: then clearly Bender's dating service is not for you

0:00 * justin_smith has his relationship fulfillment meter idling at NaN

0:21 AeroNotix: I have a gen-interface that depends on the output of a gen-class. I have them both in AOT in the dependency order. It won't compile claiming it can't find the gen-class class on the classpath. Do I need to do anything else?

0:22 justin_smith: AeroNotix: do you import the needed gen-class generated class in the ns that creates the interface?

0:23 AeroNotix: justin_smith: yaeh

0:23 yeah*

0:26 justin_smith: was there a follow-up to that or were you just making sure?

0:27 justin_smith: AeroNotix: just ruling out something simple

0:27 AeroNotix: cool ok

0:27 justin_smith: I have little experience with gen-class or gen-interface, so I can't be much help on this count

0:28 amalloy: does your interface-ns require the class-ns?

0:28 if it doesn't, the order they're compiled in will be arbitrary

0:28 AeroNotix: amalloy: imports it

0:28 amalloy: do both

0:28 AeroNotix: ok

0:29 justin_smith: ahh, yeah, good call. If not for the vodka I might of remembered that.

0:29 (inc amalloy)

0:29 lazybot: ⇒ 232

0:29 AeroNotix: amalloy: magic

0:29 (inc amalloy)

0:29 lazybot: ⇒ 233

0:29 amalloy: good to hear it

0:29 AeroNotix: Why did that fix it?

0:29 justin_smith: AeroNotix: loading the clojure code creates the class

0:30 AeroNotix: ohhh ok, the AOT, it does nothing?

0:30 justin_smith: AeroNotix: I dunno, depends on how you set lein up. It probably got the ordering wrong or something.

0:31 AeroNotix: interesting ok, thanks all

0:31 the really cool thing is, I can create a jar that just all magically looks like Java and pass it to co-workers.

0:31 amazing

0:32 justin_smith: haha

0:32 amalloy: AeroNotix: while AOTing, the namespaces have to be loaded in some order, right? and the classes are created in the same order as the namespaces

0:32 justin_smith: until they try to run a static analysis tool or something :)

0:32 AeroNotix: amalloy: right that makes sense

0:32 amalloy: so, if you don't tell clojure what order to compile the files in, it can't AOT

0:32 AeroNotix: justin_smith: they know it is clojure. I just don't want them to deal with any idiosyncrasies

0:33 all in all, Clojure helped me bridge a gap between two teams that were marred with politics

0:33 just by being able to drop them some easily consumed code

0:33 justin_smith: nice

0:33 AeroNotix: yeah I'm really happy with that

0:33 amalloy: AeroNotix: personally i'd rather write java interfaces and classes in java, vs writing them in clojure with a gen-class, but whatever works for you

0:34 AeroNotix: amalloy: I was going to do that if it didn't work but I wanted to see how far I could go with just writing clojure. Turns out, all the way nearly!

0:34 justin_smith: AeroNotix: my experience was having success sneaking some clojure into a backend stack, and then the client had a security issue with another contractor, which led to mandatory static analysis for everyone, which led to much wtf, wailing, and gnashing of teeth

0:34 AeroNotix: justin_smith: how does it manifest?

0:34 just "oh wait this is clojure wtf'

0:35 or some other aspect?

0:35 justin_smith: that plus "sorry, you can't deploy this code because we can't statically analyze it"

0:36 AeroNotix: ah, I don't *think* I'll have that issue. We'll see.

0:36 I've made it very clear what I am doing to all involved

1:30 lvh: Hi :-) I'm trying to figure out how to use core.async. I have a bunch of work items (data structures describing what to do). I want to execute them with limited parallelism. pipeline-* seems ideal. However, each of the processes relies on some continuously changing shared state of the world. I figured I'd make that a channel that gets updated whenever a new state-of-the-world is available). However; how do I do that with pipeline? I only get to pass one xform.

1:30 Does that mean I have to write my own transducer that mults in the nullary case?

2:45 SagiCZ: is clojure using new java 8 features like lambdas and Iterable/forEach()? or is that just syntactic sugar?

2:59 amalloy: clojure supports java 6

3:59 expez: when lein repl says it couldn't locate something on cp and refuses to start, what could be wrong when the jar is present in .m2 as expected?

4:33 justin_smith: expez: what's the specific error message?

4:34 expez: justin_smith: I was trying to include alembic as a dependency in refactor-nrepl (to get rid of pomegranate) but I don't think that's possible. I think the user has to include it as a dependency in the toplevel project or in profiles.clj

4:35 justin_smith: expez: alembic uses pomegranate doesn't it?

4:35 expez: justin_smith: yes, but in an isolated classloader

4:46 justin_smith: SagiCZ: some day, Clojure might directly use that java 8 stuff, but for now Clojure itself targets 1.6 (there's some cool stuff in 1.7 that isn't even used by core yet). But we can use it all via interop.

4:48 SagiCZ: justin_smith: i see.. thanks and do you have any idea if it would have any performance impact on clojure?

4:48 justin_smith: I really don't know.

4:48 SagiCZ: alright

5:36 wizzo: in this https://github.com/bbatsov/clojure-style-guide it says to prefer nil punning over empty?

5:36 is that true? why?

5:37 justin_smith: I dunno, I never really liked that rule myself.

5:41 amalloy: the rule that clojure/corepromulgated is to prefer using seq over (not (empty? ...))

5:42 choose between nil punning or empty? based on which reads better in context; since seq and empty? are opposites, you can use them to reorder your then/else clauses

5:42 wizzo: ahh ok i didn't notice the not

5:42 but why? performance?

5:43 amalloy: because it's dumb to write (not (empty? x)), when empty? is (not (seq x))

5:43 wizzo: oooooh

5:43 justin_smith: (seq x) reads better than (not (empty? x))

5:43 amalloy: (if (not (not (seq x))) (srsly what am i (doing (pls help))))

5:43 justin_smith: (not (not (not (not (seq x)))))

5:44 wizzo: eh i think not empty? reads better but that's just me

5:44 justin_smith: I'm a fan of not-empty

5:44 wizzo: but it makes sense knowing what empty? actually is

5:44 justin_smith: ,(not-empty "")

5:44 clojurebot: nil

5:44 justin_smith: ,(not-empty "hi")

5:44 clojurebot: "hi"

5:44 justin_smith: ,(seq "hi")

5:44 clojurebot: (\h \i)

5:45 amalloy: justin_smith: gross

5:45 not-empty shouldn't be used as a predicate

5:45 wizzo: why

5:46 justin_smith: amalloy: not-empty + if-let = chocolate + peanut butter

5:46 amalloy: because it's just a longer way of writing seq

5:46 justin_smith: for sure. but that's not using it as a predicate

5:46 justin_smith: it's using it as a binding and a predicate, that's what if-let is for

5:47 amalloy: that's fine. but it sounded like you were saying to use not-empty instead of (not (empty?))

5:47 since in the middle of that discussion you said "i'm a fan of not-empty"

5:49 justin_smith: yeah, I actually like using it in predicates as well (because seq is more overloaded, and the name not-empty describes what I am checking for)

5:49 but we have had this conversation before, and I understand that we disagree.

6:03 mbac: is there a way to take a sub-array from an array without copying?

6:04 justin_smith: mbac: subvec for vectors

6:04 mbac: i'm specifically using arrays tho : /

6:04 tomjack: you basically have to carry your endpoints around with you, I think

6:05 justin_smith: yeah, I think that's pretty much the deal

6:05 * mbac shakes fist at java

6:05 doritostains: exit

6:05 mbac: k

6:23 justin_smith: the most common street name in the US is second, second place is third, and third most common is first

6:34 AimHere: justin_smith, Makes sense. Some early towns started out as just being a single street. If you only have one thing, you don't call it 'first'

6:35 It's only if you have enough forethought to plan two or more streets in advance that 'first' would be in the running

6:35 justin_smith: right, I just like that the first three popular names are a perfect jumble

6:35 AimHere: It's not a complete jumble. I imagine that other than 'first', the other 'numbered' streets are more or less in numerical order

6:35 justin_smith: often instead of "first" you have "name of town" or "main"

6:35 AimHere: the first three are though

6:36 http://www.usd116.org/profdev/ahtc/lessons/PlautFel09/scans/2009_07_09/StreetNamesCensus.pdf

6:36 fourth is fourth

6:36 AimHere: Nah, 'first' is the only one out of sequence

6:36 godd2: The explanation that "first street gets renamed" makes most sense to me

6:37 AimHere: Why would first be renamed more often than second?

6:37 justin_smith: AimHere: there is no ordered permutation of 1,2,3 where no item has itself as its position, and no pair are in order

6:37 I was referring to the former property

6:38 I would hardly call 3,2,1 a jumble

6:38 godd2: AimHere it gets renamed to Main st!

6:38 AimHere: godd2, wouldn't it be called main to begin with?

6:38 godd2: That would require forsight

6:38 AimHere: Since the next few streets wouldn't be '2nd' or '3rd' but all the ones perpendicular

6:38 justin_smith: look at history: the road comes first, then the town, for a majority of towns

6:39 except the largest cities, there the port comes first

6:39 AimHere: The 1st, 2nd, 3rd tend to be parallel

6:39 justin_smith: then the roads

6:40 godd2: sometimes the river comes first

6:40 AimHere: godd2, calling it 'first' would require foresight, since then you have to presume the town will get big enough to support at least 2, and more likely 3 more roads

6:40 justin_smith: godd2: I should have generalized "port"

6:40 dock?

6:41 AimHere: I wonder how many towns had the airport first

6:41 godd2: AimHere that's true, but I still like the explanation :P

6:41 justin_smith: anyway, first you have a road, then people live near it, and finally you get parallel streets, this was the pattern through much of the US at least

6:41 AimHere: maybe some places like Alaska?

6:42 some day we may have cities where the launching pad back to earth comes first

6:43 AimHere: does anything in antarctica count as a city? if so, things are definitely built around the airfields there

6:44 AimHere: Largest settlement is that McMurdo sound

6:44 justin_smith: or town even

6:44 AimHere: And it's beside a body of water

6:44 justin_smith: yeah

6:44 AimHere: Also, 1200 residents, so a hefty village, if not a town

6:45 justin_smith: but nobody permanent

6:45 I bet 0 children

6:53 mbac: how is there really no fast Object[] getSubArray(Object[] array,int off,int len) function?

6:53 justin_smith: it could be done as a wrapper pretty easily by closing over the array

6:54 mbac: it's clearly a net loss for everyone who wants to have fast subarrays to carry around endpoints and also hope everyone who implements a library that operates on arrays provides methods that take an off and len parameter

6:54 yeah, i'm just kind of baffled by the java ecosystem

6:55 justin_smith: I bet 0 children

6:55 oops

7:26 profil: Is there a way to get an overview of threads running in the REPL?

7:26 justin_smith: (Thread/getAllStackTraces) will show you what they are doing

7:28 well, it returns a Map from Thread to StackTraceElement[] for all running threads, that can be used to find out what they are doing

7:30 profil: oh, alright

7:31 justin_smith: each StackTraceElement can then be queried for the method name, file name, etc.

7:33 profil: I am unsure if I am doing async tcp correctly..

7:35 justin_smith: have you got any experience with aleph?

7:36 justin_smith: no, I haven't used it actually. I've read a bunch of the code though

7:39 profil: okay, I am trying to figure out the periodically function from manifold.stream but I cant get my head around it

7:39 it keeps running even though I have closed the stream

7:46 justin_smith: profil: just realized that "status of all threads" function would be really useful https://www.refheap.com/98179

7:48 profil: nice

7:48 thats a lot of stuff :D

7:48 justin_smith: yeah, especially if nrepl is running

7:48 notice how many of the threads are executing nrepl stuff

7:50 profil: well, if no-one else can help, ztellman is often here, and hopefully he at least understands what it is doing :)

7:50 profil: yeah, I have looked for him the last couple of days, but missed him :)

7:53 justin_smith: profil: reading the source, I would expect it to continue even if the stream was closed

7:53 https://github.com/ztellman/manifold/blob/master/src/manifold/stream.clj#L497

7:53 it catches Throwable

7:54 so even an Error won't break out

7:54 profil: yeah, but if L506 is true it will break out? or am I wrong?

7:54 justin_smith: unless I am misreading

7:55 profil: (@cancel) means that the every function will be canceled?

7:56 justin_smith: hmm...

7:56 it depends on what time/every does I guess

7:56 profil: From time/every, "Returns a zero-argument function which, when invoked, cancels the repeated invocation."

7:56 justin_smith: https://github.com/ztellman/manifold/blob/master/src/manifold/time.clj#L159 every will keep calling the function

7:57 ahh

7:57 profil: that means that if the stream that put! tries to access is closed it will return nil, which would cancel the repeat?

7:57 but my function keeps on running 3 times after the stream is closed

7:57 just 3 times

7:57 very weird

7:58 justin_smith: that is weird

7:58 I see what it's doing with cancel now

7:59 profil: could this be a race, where there are puts that have not been consumed?

7:59 (at the time of cancellation, that is)

8:00 profil: justin_smith: yeah probably, I am connecting this stream to another where map is running

8:01 justin_smith: this is what my handler is doing, https://www.refheap.com/98180

8:01 justin_smith: if I remove line 11, the last "Ping timeout" will be printed 3 times

8:03 justin_smith: profil: at 5 second intervals?

8:03 profil: justin_smith: yes

8:04 justin_smith: but it looked like periodically was checking for the channel being closed

8:05 profil: maybe something to do with the buffering on the stream?

8:05 profil: if the stream is closed put! will return nil

8:05 justin_smith: nil, or something that derefs to nil?

8:05 because the code is dereffing

8:06 ,@nil

8:06 clojurebot: #<NullPointerException java.lang.NullPointerException>

8:07 profil: defers to nil I guess

8:07 s/fer/ref/

8:07 justin_smith: I guess that's moot beacause either way you get a cancel / close

8:08 profil: ,(let [d (future nil)] (if @d "true" "false"))

8:08 clojurebot: #<SecurityException java.lang.SecurityException: no threads please>

8:09 justin_smith: ,(let [d (delay nil)] (if @d true false))

8:09 clojurebot: false

8:14 profil: I am not fiddling with buffering on the stream myself

8:14 I have no idea why it does that

8:36 nicferrier: hey all ... still arsing around with zippers and hiccup.

8:37 I can see it's a powerful technique, but it seems like the xml.zip package has some pretty basic utils that hiccup doesn't have.

8:37 should I abandon hiccup and try and make my data parsable by the standard xml stuff? is that a more normal way to work with xml data in clojure?

8:38 irctc__: Hello ... I'm trying to call a Java method from AClass in Clojure that receives as parameter AnotherClass.class. Not a instance, but the class itself. How can I do that?

8:41 I've tried (class AnotherClass) but it returns java.lang.Class instead of com.package.AnotherClass.class or something.

8:43 nicferrier: have you imported AnotherClass?

8:44 irctc__: Yes... like (:import (com.package AnotherClass)

8:44 Yes... like (:import (com.package AnotherClass))

8:44 nicferrier: can't you just (somefunc 'AnotherClass) ?

8:44 irctc__: The exception is: java.lang.IllegalArgumentException: No matching method found

8:45 nicferrier: is it a static method?

8:45 irctc__: No, I need an instance of the class to invoke it....

8:46 nicferrier: so it's an instance method?

8:46 and you've got the instance?

8:46 irctc__: I'm trying to wrapper this: https://github.com/EsmerilProgramming/graesh/blob/master/src/main/groovy/org/esmerilprogramming/graesh/Graesh.groovy

8:47 The equivalent of Line 47 not working here.

8:47 Hey @nicterrier, thanks a lot for your attention by the way :-)

8:48 nicferrier: so you have something like this (let [a (AeshCommandRegistryBuilder.) b (.commands a AnotherClass)] ...)

8:49 TimMc: irctc__: Does commands take varargs?

8:49 irctc__: (defn init-aesh-command-registry-builder [] (doto (AeshCommandRegistryBuilder.) (.commands (class Cat) (class Cd))))

8:50 nicferrier: irctc__: but you need to pass in the instance to .commands

8:50 TimMc: (.commands builder (into-array Class [Cd Ls Mkdir]))

8:50 irctc__: (class Cat) will give you Class.

8:50 elsen: hola

8:50 irctc__: Hum. But (doto) does that, no ?

8:50 elsen: anyone using clojure on android?

8:51 irctc__: (doto (AeshCommandRegistryBuilder.) (.commands (class Cat) (class Cd)))

8:52 The Java method has this interface: public AeshCommandRegistryBuilder commands(Class<? extends Command>... commands)

8:54 martinklepsch: probably a dumb q: I have a list [a b c] now I want to apply f to each possible combination of two items ignoring how they're ordered (e.g. apply f only to [a b] but not [b a]) — I'm sure there is a word for that kind of thing?

8:57 irctc__: It's a combination @martinklepsch

8:59 Try (:require [clojure.math.combinatorics :as combo])

8:59 TimMc: irctc__: Right, so like I said above, that's varargs.

9:00 irctc__: Try the thing I showed you above.

9:00 irctc__: (combo/combinations seq 2)

9:00 borkdude: I saw someone type this on twitter:

9:00 ,(identical? 'a 'a)

9:01 clojurebot: false

9:01 borkdude: why is it false again?

9:01 irctc__: (class Cat) gave me java.lang.Class :-(

9:01 martinklepsch: ,(prn 'a)

9:01 clojurebot: a\n

9:02 martinklepsch: ,(println 'a)

9:02 clojurebot: a\n

9:02 borkdude: symbols are not interned like string literals?

9:03 martinklepsch: dont know, was just guessing that it could be because of some gensym stuff

9:03 irctc__: I have found this: http://tech.puredanger.com/2010/08/08/learning-clojure-class-reference/

9:03 TimMc: irctc__: You should the above IRC messages more carefully.

9:03 irctc__: Trying to understand.

9:04 martinklepsch: irctc__: thanks, I somehow assumed that a "combination" would include dupes as in [a b] [b a]

9:04 TimMc: ,(class "foo")

9:04 clojurebot: java.lang.String

9:04 TimMc: ,(class java.lang.String)

9:04 clojurebot: java.lang.Class

9:04 irctc__: Do you mean (.commands builder (into-array Class [Cd Ls Mkdir])) ?

9:05 TimMc: yes

9:05 irctc__: trying...

9:06 Not yet... :( more tries

9:09 It compiles!

9:10 Thanks TimMc !!

9:16 TimMc: sure thing

9:16 Go read up on varargs, they're weird. :-P

9:17 ,(String/format "%s %s" (to-array [5 :cats]))

9:17 clojurebot: "5 :cats"

9:18 gfredericks: TimMc "5 :cats" is an acceptable baby name I think

9:19 TimMc: I think so too, will mention it to Alex.

9:19 gfredericks: does the jvm have different endianness details from Normal Honest To Goodness C Code?

9:20 in particular I'm writing ints to a DataOutputStream which is going to standard out and into a Normal Honest To Goodness C Program

9:21 oh wait nevermind

9:21 the bytes are probably different but the bits within the bytes are not (is that even plausible?)

9:40 dysfun: is there any way to abort a System/exit ? i would like to ensure my function tries to exit during a test

9:44 gfredericks: dysfun: you could switch to using https://github.com/gfredericks/system-slash-exit ;-)

9:47 dysfun: gfredericks: <3

9:48 i was going to write something similar heh

9:48 gosh, no tests though. i mean there's a whole line of code there actually doing something. can't be sure it'll work.

9:52 gfredericks: you need to create a shorter name though.(require '[com.gfredericks.system-slash-exit :refer [exit]]) isn't exactly concise

Logging service provided by n01se.net