Fork me on GitHub
#clojure
<
2016-05-02
>
hlolli08:05:05

I notice some difference in sorting with clj-time and cljs-time. I can sort timestamps like this in cljs (sort #(t/before? (t/date-time %1) (t/date-time %2)) '(#inst "2016-03...etc.." ..etc..)) but the same code in clj gives me java.util.Date cannot be cast to java.lang.Number anyone know how to sort by timestamps in clj-time?

hlolli08:05:50

doing (sort #(< (clj-time.coerce/to-long %1) (clj-time.coerce/to-long %2)) timestamps) does the trick.

infosophy10:05:12

@thiagofm Regarding your non-dry tests in midje - could tabular facts be what your’re looking for? https://github.com/marick/Midje/wiki/Tabular-facts

bojan.matic11:05:56

i figure a lot of you have seen rich hickey's language of the system talk

bojan.matic11:05:33

that sounds a lot like it's promoting a sort of message passing model for parts of the system

bojan.matic11:05:49

which in turn, sounds like the actor model fits the bill

bojan.matic11:05:26

but rich specifically said that he didn't want to design the language around actor model (ala erlang)

bojan.matic11:05:36

what am i missing here? possibly a whole lot of nuance

bojan.matic12:05:10

if it's a stupid question, forgive me, I'm still trying to learn simple_smile

rafa12:05:57

@bojan.matic: which talk are you specifically referring to? mind sharing a link with us?

rafa12:05:34

@bojan.matic: it’s been a while since the last time I watched “simple made easy”, but I do remember Rich mentioning that he chose CSP over actor model for simplicity reasons

rafa12:05:20

and indeed, actors are more complex machinery than queues and threads. if I understand Erlang/OTP correctly, the core concept is the tree of linked processes

rafa12:05:20

and how that helps with error handling

rafa12:05:29

@bojan.matic: please have a look at this blogpost from parallel universe giving background for creating pulsar (actor library for JVM): http://blog.paralleluniverse.co/2013/05/02/quasar-pulsar/

rafa12:05:50

>Rich Hickey, Clojure’s designer, has made it very clear why he chose not to have Erlang-style actors in Clojure. His makes some good arguments, and far be it from me to disagree with Hickey on Clojure’s philosophy, but I think that that reasoning, too, serves programming-in-the-small rather than in the-large. Actors, in addition to their contribution to simplifying concurrency, help isolate and handle errors. In fact, that is why they’re used in Erlang in the first place. Actors in Clojure may be a tool for programming-in-the-large.

bojan.matic12:05:34

i saw that post, that is why i'm asking this question simple_smile

thiagofm13:05:14

@infosophy: not entirely. I don't really want the table, what I've wanted was a way to specify I want to test a function, and then use the normal => syntax for the args. But thanks a lot!

patrkris14:05:26

Hi there. Is there an idiomatic way of swallowing an exception and returning nil if one occurs?

cpmcdaniel14:05:42

it is common clojure style to name predicate fns, macros, etc with a ? suffix - what about boolean values, like in a let binding? Style guide is silent on this. Is it confusing to name boolean values like 'found-the-thing?'

cpmcdaniel14:05:59

@patrkris: just catch Throwable and return nil

cpmcdaniel14:05:24

if you are doing this often, maybe write a macro for it

patrkris14:05:53

@cpmcdaniel: that's what I ended up doing, but thought maybe it's such a common use case that Clojure already had a solution

nkraft15:05:23

@seancorfield: Actually, the ring server has no problem finding the views, which are the Selmer templates to be rendered. It renders the view fine, but the css and js files referenced in the template are not found, pretty much no matter how I specify the paths. It's kind of odd. Hiccup had no problem rendering the page with the included css and js, but it was too limited for my needs.

hiredman16:05:33

it is likely you changed something else when you switched to selmer, like removed the resources middleware

seancorfield16:05:49

Yeah, I asked @nkraft about resource middleware earlier. Using Selmer vs Hiccup has absolutely no bearing on whether a given URL to a static file will render via Ring.

nkraft16:05:04

Which resources middleware would have changed or been removed?

hiredman16:05:35

just look at what else you changed since it last worked

nkraft16:05:54

The handler code hasn't changed since I changed template processors.

nkraft16:05:29

I have ring-middleware-defaults and ring-middleware-parms required.

seancorfield16:05:04

Look at the source of the generated page in the browser, produced by each template engine. Compare the URLs to the static assets.

hiredman16:05:41

requiring middleware doesn't mean you are using it, your handler needs to be wrapped in it

hiredman16:05:20

did you change versions of ring-middleware-defaults? (whatever that is?) if you did, they could have changed

nkraft16:05:24

The handler is wrapped.

nkraft16:05:37

No, that hasn't changed.

nkraft16:05:52

Yes, Sean's idea seems to be the best of the recommendations so far.

nkraft16:05:26

I don't do a lot of front end stuff, mostly just back end, compojure for APIs, stuff like that. Haven't tried clojure templates before so this is a learning process.

seancorfield16:05:58

If the assets load in one case and not the other, then you’ve changed how you generate those URLs and that is the problem — and its independent of whether you’re using Hiccup or Selmer or Mustache or whatever.

seancorfield16:05:30

(and technically this is back end, not front end, since you’re generating the HTML on the server 😄 )

neverfox16:05:48

Ran into this myself just now with a different annotation that expects an integer, getting the same errors. Does anyone know the secret to this or is it just one of the places where interop is limited? http://stackoverflow.com/questions/18280626/clojure-annotations-and-integers

nkraft16:05:05

Not my idea of back end. I work mostly with APIs and big data implementations. Anything a user can see is "front end" to me. simple_smile

nkraft17:05:47

I've always used Python for HTML generation, but I'd like to get this going with Clojure.

seancorfield17:05:34

I understand. I try to avoid HTML / CSS / JS too, but I’ve had to build a bunch of stuff with Hiccup and Selmer where I’m generating some crazy complex stuff on the server.

sekao17:05:16

does anyone have a simple way of making a fork that doesn’t conflict with the original version? i forked tools.reader, but the only way i can use it is by carefully excluding the original tools.reader from any dependency that uses it. it would be nicer if i could just rename the namespaces, but i don’t know how to do that short of changing every file in the fork.

Alan Thompson17:05:18

Hey @gjnoonan , how can I turn off meekan notifications for everything in my Google Calendar? It is most annoying!!!

seancorfield17:05:55

@cloojure: That doesn’t sound like a Clojure question — was it meant for another channel/room?

Alan Thompson17:05:48

The bot that is installed by default is named "meekan". I already asked the slack people how to disable it and they said I have to talk to the Clojure room moderators.

seancorfield17:05:11

Try #C04V84U7G then?

seancorfield17:05:12

(I’m one of the admins but I’ve never heard of meekan)

jjttjj17:05:34

how do people feel about global state management in clojurescript compared to a backend clojure application? Over the past months i've fully adopted Component on the server side and thoroughly enjoy the repl experience it allows. It has influenced the way I am now building up a client side app. I'm passing local state down the ladder everywhere, taking state as args instead of referring to a global. While this keeps things a little organized, it's also seeming to put a strain on front end api, having to pass around resources everywhere where it would be easier just to silently depend on something like a singleton async channel, and the gains are less pronounced because on the frontend my workflow is based around page refreshes instead of resetting the repl (and i'm fine with this). Basically, is it common for state management to be less strict on client side applications?

gjnoonan17:05:51

@cloojure: @seancorfield I nevr installed meekan either, but will have a look

seancorfield17:05:05

@jjttjj: I’m not sure what’s considered best practice these days but there are #C03S1L9DN #C0620C0C8 and #C06DT2YSY channels where I bet you’ll get more opinions… Last time I did any cljs the wisdom seemed to be a single global atom but maybe that’s changed.

jjttjj17:05:35

seancorfield: Thanks I'll ask again in #C03S1L9DN

scriptor20:05:10

any way I can parameterize the value for an IN clause using java.jdbc?

ddellacosta20:05:29

@scriptor: it’ll be a lot easier if you can use HoneySQL for that

ddellacosta20:05:06

(j/query db (hsql/format (hsql/build :select :foo :from :bar :where [:in :a some-coll]))) for example

ddellacosta20:05:07

otherwise, probably some way to build up the string yourself, just more work

ddellacosta20:05:29

and HoneySQL will handle making it a prepared statement for you, so it’s safer in that sense

ddellacosta20:05:55

> (hsql/format (hsql/build :select :foo :from :bar :where [:in :a ["a" "b" "c"]]))
["SELECT foo FROM bar WHERE (a in (?, ?, ?))" "a" "b" "c”]

ddellacosta20:05:18

</end HoneySQL sales pitch>

scriptor20:05:02

ddellacosta: gotcha, is there a practical limit to how big of a collection I can throw in there?

ddellacosta20:05:45

@scriptor: that I don’t know…if I had to guess I would guess it’s whatever (clojure.)java.jdbc limits you to

ddellacosta20:05:50

but I don’t know

scriptor20:05:31

fair enough, thanks for the help!

curtis.summers20:05:35

@scriptor The limit is based on your underlying JDBC driver. It differs for each driver based on the max parameter binding limit.

ddellacosta20:05:53

there ya go, thanks @curtis.summers , didn’t know that

curtis.summers20:05:26

Also, you might check out my library for "SQL-first" workflow: http://www.hugsql.org

curtis.summers20:05:41

IN (...) clause is handled by value list parameters: http://www.hugsql.org/#param-value-list

scriptor20:05:13

@curtis.summers: any idea what the name of that setting is?

curtis.summers20:05:53

I don't believe it is configurable. See this comment on this issue: https://github.com/layerware/hugsql/issues/22#issuecomment-188353269

ag20:05:59

how can I attach docstring to a keyword? e.g.

(def foo {:bar ^{:doc “this is bar” } 42})

curtis.summers20:05:21

@scriptor So, some of the limits we've seen: 8k for SQLite, 32k for Postgresql, and ~2k for SQL Server.

seancorfield20:05:15

I read somewhere that SQLite used to be 999 and it seems like Oracle has (or had?) a limit of 1000… So it’s probably fair to say that "about 1,000" is a portable limit?

curtis.summers20:05:12

@ag I don't think you can attach metadata to keywords. Trying to find the documentation on this...

flyboarder21:05:27

hey guys im trying to write a macro that acts just like the threading macro, except decorates all of it’s arguments, does anyone have something similar i might be able to look at?

c0rrzin22:05:21

does anyone know why trailing colons (in symbols) are reserved in clojure? I tried but haven’t found a reason for that.

flyboarder22:05:27

@darwin: I was looking there but i thought that might be overly complicated. What I am trying to do is take (my-> arg1 arg2 arg3 ...) and turn it into (-> (fn1 arg1) (fn2 arg2) (fn2 arg3) (fn2 arg4) ...)

flyboarder22:05:03

i thought I could figure this out with some unquote splicing

darwin22:05:44

@flyboarder: only that first arg has fn1 or is it a typo?

darwin22:05:15

fn1 and fn2 are hardcoded?

flyboarder22:05:24

@darwin: im trying that now simple_smile yes fn1 and fn2 are hard coded

flyboarder23:05:03

@darwin: that almost gets me there, the problem is that fn2 is interop so it gets broken into (. (fn1 arg1) fn2 arg2)

flyboarder23:05:20

instead of .fn2

flyboarder23:05:43

@darwin: i moved interop to it’s own function and that seems to work thanks so much!

darwin23:05:42

(.fn o 1 2 3) macroexpands to (. o fn 1 2 3) so you should plan accordingly

flyboarder23:05:01

@darwin: do you have a suggestion for that case?

darwin23:05:06

how exactly did you invoke the my-> macro and what was its source?

darwin23:05:44

let me macroexpand it

paul4nandez23:05:52

Anyone ever notice inconsistent behavior with comparison operators and sorting? For instance, (< -1 nil) returns true, but (sort [-1 0 1 nil]) returns (nil -1 0 1).

darwin23:05:50

@flyboarder: all looks good here, (. (fn1 arg1) fn2 arg2) is correct output, it is expanded (.fn2 (fn1 arg1) arg2), both mean the same thing

darwin23:05:13

use macroexpand-1 to see only one macroexpansion step at time

bostonaholic23:05:57

@paul4nandez: sort uses compare not <

bostonaholic23:05:40

user=> (compare -1 nil)
1

bostonaholic23:05:53

-1 is ‘greater than’ nil

paul4nandez23:05:53

Yes, nil is supposed to be less than everything.

flyboarder23:05:13

@darwin: it's working for me, much appreciated!!!

paul4nandez23:05:34

But (< -1 nil) says otherwise.

bostonaholic23:05:02

actually, I’m getting NullPointerException for (< -1 nil)

paul4nandez23:05:27

That's actually somewhat encouraging (I guess).

paul4nandez23:05:02

I'm seeing this in a Planck repl, so it could be a bug there.

bostonaholic23:05:36

ah, so clojurescript

bostonaholic23:05:41

different animal

bostonaholic23:05:54

> WARNING: cljs.core/<, all arguments must be numbers, got [number clj-nil] instead. at line 1

paul4nandez23:05:31

It seems so. I just checked it in intellij and get a warning in clj and exception in cljs.

bostonaholic23:05:58

I think you mean the other way around

bostonaholic23:05:07

warning in cljs, exception in clj

paul4nandez23:05:36

Right. Yes. So I guess the moral here is to make sure its a number before comparing. simple_smile

bostonaholic23:05:54

or use compare

bostonaholic23:05:35

read the explanation in (source compare) in planck

paul4nandez23:05:58

Yep. "...special-cases nil to be less than any other object."

paul4nandez23:05:17

Still seems a bit inconsistent to have < and > treat it otherwise though. Thanks for the insight.

bostonaholic23:05:42

I agree it’s probably not what you expected to happen

bostonaholic23:05:28

but if you can’t guarantee both arguments to be Number, then you’re at the mercy of JavaScript object comparison