Fork me on GitHub
#clojure
<
2016-01-30
>
jonahbenton00:01:35

@shriphani: can you say more about the error you got with eastwood?

shriphani00:01:32

ah actually it was bikeshed not eastwood: and the gist is: Checking for arguments colliding with clojure.core functions. Subprocess failed

jonahbenton03:01:05

@shriphani: there is an issue on github of a similar issue: https://github.com/dakrone/lein-bikeshed/issues/12 it sounds as though it is finding a collision, but failing to report it. perhaps you can comment on that issue?

asolovyov10:01:22

I'm writing a macro and I receive it's arguments as [& args]. In the context of compiling to clojurescript, those args are a list. But in context of compiling to clojure, they are ArraySeq. I'm wondering what's the difference, what's ArraySeq and what's the best way to check for it?

hans10:01:40

asolovyov: how does it matter to you? seems to be an implementation detail to me.

asolovyov10:01:44

@hans: well, I'm changing someone's library and to check it's a function body it does (and (list? body) (vector? (first body)). I wonder if I can break anything by changing list? to seq? simple_smile

hans10:01:45

if the macro's signature is [ & body ], the check is rather redundant.

hans10:01:57

i'd just remove it.

asolovyov10:01:03

well, it's a bit more complicated... https://github.com/tonsky/rum/blob/gh-pages/src/rum/core.clj#L9 if you're interested

asolovyov10:01:15

I think I'll change to seq? and will see how that works

hans10:01:22

should do fine.

asolovyov10:01:40

{} and "" and not seq?, so I should be safe

asolovyov11:01:16

is it possible to output something in macro only if it's not nil?

ezmiller12:01:43

is there a quick way to get a utc timestamp in clojure, ie. without loading clj-time and so on?

jplaza12:01:19

I think that you need to take the Java path for this. As far as I know there are no date primitive in CLJ (defn now [] (new java.util.Date))

jethroksy12:01:17

(defn now [] (java.util.Date.)) is slightly more idiomatic

jethroksy12:01:33

depending on your usecase for the utc timestamp, it might be better to import clj-time

pguillebert12:01:31

and/or System/currentTimeMillis which is way faster

pguillebert12:01:02

depending on your need

ezmiller12:01:21

I’m actually just using it to generate a random token

ezmiller12:01:47

when i try (defn now [] (java.util.Date.)) , and the call it, i’m getting a java is not defined error. i suspect this is because i’m using figwheel and i’m really using clojurescript and not clojure?

jethroksy12:01:04

oh... wrong channel

ezmiller12:01:23

i’m still fuzzy on the difference between the two — sorry i’m a newb

ezmiller12:01:44

clojurescript has interop access to javascript instead of java?

jethroksy12:01:49

something along the lines of (js/Date ...)

jethroksy12:01:01

js exposes the javascript namespace

ezmiller12:01:30

yeah i’ve been using js/… but i guess i thought i had access to the java fns also.

jethroksy12:01:52

cljs.user=> (. js/Date now)
1454156773612

pguillebert12:01:51

ezmiller: clojurescript looks the same for the clojure part, but of course when using the underlying host platform (java for clojure, js for clojurescript, or event .NET for clojureCLR) it becomes different

ezmiller12:01:30

okay, got it. makes perfect sense

ezmiller12:01:00

in clojure, what is the (System/…) referencing by the way?

jaen12:01:24

Class/staticMethod is for referencing static methods of classes.

pguillebert12:01:18

oh and if all you need is a random string, UUID may be of interest

asolovyov12:01:56

well, there is no UUID in the browser simple_smile So (.now js/Date) should be ok.

solicode12:01:15

ClojureScript has a function for that. (random-uuid)

asolovyov12:01:21

any pointers why lein run -m my.ns fails with Cannot find anything to run for though I have -main defined?

jaen12:01:42

You have :gen-class on your main ns?

asolovyov12:01:23

I've added it, but it didn't help... 😕

solicode13:01:40

And I'm assuming you defined -main in my.ns and not in some other namespace in the project? The error makes it sound like it's not in that namespace.

asolovyov13:01:29

it indeed sounds like I haven't defined -main, but I certainly did! simple_smile

asolovyov13:01:52

I can even run it from the repl:

user=> (rum.server-examples/-main)
[:div Static :  [:span {:style {:color #FA8D97}} 15:00]]
nil

asolovyov13:01:05

But:

> lein run -m rum.server_examples
Exception in thread "main" java.lang.Exception: Cannot find anything to run for: rum.server_examples

asolovyov13:01:21

that's all because of file completion

asolovyov13:01:33

huh, it works

solicode13:01:09

Hmm, it works? I would have expected the problem to be underscore vs hyphen there. lein run -m rum.server-examples not lein run -m rum.server_examples

solicode13:01:02

Oh, that’s maybe what you meant with file completion?

asolovyov13:01:51

yeah, I've completed with an underscore and didn't notice until posting command here...

solicode13:01:18

Ah, I see. Makes sense.

ezmiller15:01:13

anyone know of a good style guide (re indentation, etc) for clojure?

ezmiller15:01:55

or: how would you all format a multi line fn shortcut with the #(…) syntax

ezmiller15:01:02

jethroksy: thanks!

jaen15:01:44

Basically if it's multi-line I'd start thinking to use (fn [...] ...) instead.

jaen15:01:24

#(...) should be used only when it's short and obvious; I'm not sure multi-line would qualify.

ezmiller15:01:28

jaen: yeah i was thinking tha tmight be the way to go.

jethroksy15:01:01

things can get a little obtuse

kingoftheknoll15:01:37

Does anyone know if immutant or http-kit do concurrent request/response for regular http requests? Both docs appear to only mention concurrent stuff for websocket connections.

kingoftheknoll15:01:37

Application I'm working on has potentially long db IO time and I don't want the web server to block

jethroksy15:01:18

what you're looking for is asynchronous connections

jethroksy15:01:39

there are tons of options here

jethroksy15:01:03

all the ones you mentioned should have support for that

kingoftheknoll15:01:30

Great, thanks for the quick response. I'm wondering if they do that automatically out of the box because I didn't see anything about configuring that. I'll go through the docs again

jethroksy15:01:45

which do you intend to use?

jethroksy15:01:06

http-kit is less maintained, so i'd suggest immutant

jethroksy15:01:14

there's also aleph and catacumba

kingoftheknoll15:01:32

I'm leaning towards immutant but I don't plan on using any of the wildfly stuff

kingoftheknoll15:01:25

It looks like I can only use the web library though. Heard good stuff on aleph catacumba?

jethroksy15:01:16

I'm personally using aleph

jethroksy15:01:48

manifold is really powerful

kingoftheknoll15:01:10

Im not familiar with manifold, Java lib?

kingoftheknoll15:01:56

This looks very cool

jethroksy15:01:02

looked up immutant's docs, and I don't think they made it immediately clear how to make asynchronous requests, except maybe as-channel

kingoftheknoll15:01:00

yeah and most of that appeared geared towards websockets which maybe lead me off the sent

balduncle17:01:41

Does anyone know if it’s possible to specify JVM version specific :jvm-opts for lein? For example, specifying -XX:PermSize for Java 7 only so Java 8 doesn’t display warnings saying the options are being ignored?

solicode17:01:16

@balduncle: I could be wrong, but I don't think there's anything in lein to help you there. I know it’s not ideal, but the only thing I can think of is programmatically generating the :jvm-opts vector yourself in the project.clj based on the JVM version.

seancorfield17:01:12

Yes you can build the JVM opts vector dynamically based on inspecting the Java version system property. We did that at World Singles back when we were rolling out Java 8.

balduncle18:01:18

@solicode, @seancorfield, Okay, that is what I thought as well. Thank you both.

jaen19:01:20

Quick question - what do I have to implement on defrecord to make private, record-specific methods on it? Or is there no way to do so?

arohner19:01:09

@jaen: that’s not really the clojure way. You could make a protocol with only one impl, but that’s still slightly weird

arohner19:01:12

what are you trying to do?

jaen19:01:05

Yeah, figured it would be weird. Just creating a component and wanted a private helper method, so I can close over the record arguments.

jaen19:01:27

But if that's not really possible I'll just make a defn- before the record and pass the fields I need I guess.

jaen19:01:34

A bit more verbose that way, but what can you do.

arohner19:01:56

protocol impls. can refer to record args

borkdude19:01:02

@jaen maybe use a closure?

jaen19:01:00

Adding a single-method protocol also has the downside of the method being public, which I would want to avoid; it's an implementation detail I want to factor out into a common place. Though on the other hand; what's the downside of having that method public if records are immutable I suppose.

jaen19:01:14

But I guess just making a normal defn- and passing arguments is simpler.

jaen19:01:17

@borkdude: not sure how that could work - this needs to be a defrecord (using component) and the only way to close over defrecord fields I know of is to add the method to it's body.

arohner19:01:27

IMO, enforcing private is a waste of time

arohner19:01:38

just use a naming convention for ‘this is private’

arohner19:01:49

I typically use (defn foo- …)

jaen19:01:42

No, I agree; encapsulation is something created because of imperativeness and mutability none of which are pervasive in Clojure. I just feel kind of iffy exposing something like that for some reason.

jaen19:01:58

I'll just go with a private companion function you have to pass the fields to then.

seancorfield19:01:30

We stopped writing private functions completely about a year ago at work. The only things we ever make private these days is some small piece of data that is used only within a namespace (either shorthand symbols for strings and keywords to avoid misspellings or atoms for the occasional bit of mutable singleton state).

seancorfield19:01:46

And we're moving away from the latter. Slowly.

cigitia19:01:49

Does there happen to be a reference somewhere of the core Clojure protocols like those used by assoc, count, contains?, etc.?

bronsa19:01:50

they're not protocols anyway, clojure uses normal interfaces

cigitia19:01:28

And excellent; it's being looked at

cigitia19:01:57

Hopefully differences with CLJS (e.g., no IPersistentVector) will be documented too

jaen19:01:37

@seancorfield: you probably have a pretty big codebase - doesn't this make things like "I created this function for local use in the namespace, but someone used it for something else and now I can't change it" happen more often if the intent is not stated? Or you document that in comments or something?

akiva19:01:43

I still use defn- but not as some sort of OO-style guarantee of private; more as of a description of my intent. Here’s my suggested API for a namespace and these over here marked defn- are the bits behind the façade.

jaen20:01:33

Huh, anyone ever encountered something similar?

java.lang.AbstractMethodError: Method thesis/backend/components/logic/users/Users.stop()Ljava/lang/Object; is abstract

bronsa20:01:24

you probably have (defn ^long stop [] ..)

bronsa20:01:17

should be (defn stop ^long [] .. )

jaen20:01:30

(defrecord Users []
  component/Lifecycle
    (start [component]
      component)

    (start [component]
      component)

  protocols/CommandHandlerProvider
    (-get-command-handlers [this]
      {:users/create users-create-handler}))

jaen20:01:35

So no, that doesn't seem to be the case

bronsa20:01:53

how are you getting that error?

bronsa20:01:02

and what version of clojure?

solicode20:01:13

You have start twice. Is that intentional?

jaen20:01:31

Thanks ;' )

jaen20:01:38

That explains it.

jaen20:01:10

I totally did not see it looking at it for some reason.

thomas20:01:03

Hello people...

thomas20:01:48

I have a `(ns gps-tracker.handler (:gen-class))` in my file… and a :main ^:skip-aot gps-tracker.handler in my project.cljs...

thomas20:01:29

but I am getting this warning: Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.

thomas20:01:38

any idea what I could be doing wrong?

seancorfield20:01:14

@jaen: We find we get more reuse by not assuming a function should be private to a given namespace. Small, pure functions, that do some single, specific thing, often find new uses elsewhere. Then if we need to change the implementation for some of those uses, it’s reasonable to either just copy and modify the small function or add an optional keyword argument / new arity if that’s more appropriate. Of course if you copy’n’change a function, you have to pick a new name or refactor the more reused version into a different, more general namespace. We tend to do the latter.

jaen20:01:53

I see. That makes sense, I suppose. I never had to work in a big project thus far, so was curious how this approach scales to more developers.

shriphani21:01:39

Hi, there’s a java library I want to use in a clojure project. The project uses System.loadLibrary heavily and clojure versions > 1.6 don’t like it. Here’s the offending line: https://github.com/vinhkhuc/jcrfsuite/blob/4d417243802a08c3e0b7bdea9085d6bf3afc47e2/src/main/resources/crfsuite-0.12/native_loader/CrfSuiteNativeLoader.java#L28 Is there a quick solution to the problem? (i.e replace that line with something else like the clojure-specific loader). Would really like to not spend too much time rewriting that stuff.

grav22:01:35

If I have two lists of bools that I want to or pair-wise, I can do this:

(map (fn [a b] (or a b)) [true false] [false true])

grav22:01:50

But what if I have n lists? I cannot use apply, since or is a macro

jaen22:01:43

Reduce it?

jaen22:01:39

Or maybe more simply, every? for and and some for or.

grav22:01:12

ah, so I should transpose the data, i guess?

grav22:01:23

and then do some over each column

grav22:01:33

that would make sense

solicode22:01:13

@grav Do you need to transpose the data though? How about something like this?

(map #(some true? %&) [true false] [false true])

solicode22:01:34

Though you probably want to wrap that in a (boolean) if you don’t want nils

jonahbenton22:01:55

@shriphani: curious- what gets reported when the library is loaded?

jonahbenton23:01:43

@thomas: the ^:skip-aot is keeping the namespace from being compiled.

jonahbenton23:01:19

@thomas: nm, didn't see the next comment

shriphani23:01:46

@jonahbenton: sorry was afk - just one sec