Fork me on GitHub
#clojure
<
2016-08-23
>
samedhi04:08:55

(ns omni.dal.google.datastore
  (:require [st.log :as log])
  (:import [com.google.cloud.datastore Entity]))

;; Code elided, stream is a entity retrieved from the datastore.
(-> (Entity/builder stream) (.set "has_comment" true) (.build))

samedhi04:08:31

2016-08-23T04:01:51.899861+00:00 app[web.1]: Exception in thread "async-dispatch-1" java.lang.ClassCastException: Cannot cast com.google.cloud.datastore.Entity to [Lcom.google.cloud.datastore.Entity;
at java.lang.Class.cast(Class.java:3369)
at clojure.lang.Reflector.boxArg(Reflector.java:427)
at clojure.lang.Reflector.boxArgs(Reflector.java:460)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:58)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
...

samedhi04:08:51

… Just not clear what could be going wrong.

samedhi04:08:12

Why is it trying to cast anyway? It is the same thing!

seancorfield04:08:52

@samedhi Looks like it's expecting an array of Entity? The [L prefix...?

samedhi04:08:27

@seancorfield: ah…. very interesting

samedhi04:08:41

Is there a place where those sort of prefix’s are listed?

seancorfield04:08:02

You can see the [L format with (type (into-array String [])) which prints [Ljava.lang.String;

seancorfield04:08:50

Do you have a link to the javadocs for that Google stuff? Having a hard time finding the right links

seancorfield04:08:38

I can only see a static method called newBuilder on Entity, or a nested Builder class inside Entity

seancorfield04:08:37

Found it... I think ... Hmm, so Entity/builder expects either an Entity to copy from or a Key?

samedhi04:08:54

Yeah, that is what I am reading as well, but I did replace it per your first suggestion with (into-array [updated-entity]) and now it works.

samedhi04:08:36

...I think I have learned that I kind of hate the builder pattern...

seancorfield05:08:04

Yeah, I have to interact with a few Java libraries that use the builder pattern and it's a pain from Clojure sometimes due to overloading and lack of type hint in threaded forms...

seancorfield05:08:32

Glad you got it working!

onetom05:08:09

im trying to find a versioning system spec. i think i saw it on HN. you start from 1.1 and you only increment the minor number with every release. you only increment the major when you branch, but keep the minor incrementing. 1.1 -> 1.2 -> 2.3 -> 2.4 -> 1.5 -> 2.6 what was the name of this scheme?

seancorfield05:08:25

Where the minor part keeps incrementing even when you change the major part? boggle How does that convey any useful information?

hiredman05:08:08

not exactly that

hiredman05:08:42

it sounds good to me, semantic versioning never sat will with me for the reasons outlined in the mono write up. but I've never really tried to adhere to either, so I can't give a good compare and contrast

seancorfield05:08:57

I've generally found semver easier to work with since you get a simple ordering within each major version for when you release updates to older versions... I've sometimes had to maintain two major versions back and it's a lot easier for users if they get 1.2 1.3 1.4 and 2.1 2.2 2.3 etc so they are no gaps

seancorfield05:08:53

having 2.1 1.2 2.3 2.4 1.5 1.6 seems like a recipe for confusion to me

onetom05:08:01

@hiredman: that's the one i was looking for, thanks! @seancorfield: the minor version just says it's a newer version and gaps in minor version numbers indicate there was also releases on other branches too. im not sure if it's good or bad, i was just having lunch break and that's what i was thinking while i couldn't get @flyboarder's demo running because of versioning issues 🙂

hiredman05:08:23

how do you decide when to bump each of those version numbers?

seancorfield05:08:56

Heh, well, if folks use semver-looking version numbers but don't actually follow semver semantics you're in for some pain.

hiredman05:08:09

at my last job, we released every two weeks, and the "version" of the release was the date of release, with a optional patch level

hiredman05:08:32

even when you do, the semantics I think are under specified and open to interpretation

hiredman05:08:51

one person's bug is another person's feature

seancorfield05:08:03

Yeah, we tag with a date/time stamp at World Singles because it's just ongoing development on "the web apps" but as we move more toward independent libraries we'll need to adopt semver (or something else).

flyboarder05:08:11

@hiredman: I have a boot-semver task which you can use in build pipes for versioning

onetom05:08:22

well, there is http://calver.org too to consider

hiredman05:08:28

we did not use boot and did not use build pipes

hiredman05:08:57

I started there before lein was written, and phil was working there when he started the lein project

hiredman05:08:37

that is a fiar point, our other libraries tended to have something vaguely resembling semantic versioning

hiredman05:08:26

I think in a single org, where you can define the underdefined stuff inhouse, it can work

hiredman05:08:12

expecting to have the same interpretation of semver as someone else on the internet seems like how nodejs library flamewars start

hiredman05:08:47

compatibility can be tested to determine if it needs to be incremented for a release (maybe even using clojure.spec)

hiredman05:08:29

determining if the minor or patch number needs incrementing can get very nuanced

jimmy08:08:29

hey guys, recently I have a problem regarding working with repl. My flow is I often have a big chunks of code in (comment ) as a playground to trying out things in repl. The problem is when ever I evaluate the whole buffer, the whole comment area is being evaluated as well, even it doesn't do anything as expected but it slows down the evaluating process dramatically. Is there any way we can prevent this ? Thanks

iku00088808:08:52

@nxqd Use #_() if you want to completely ignore the form

jimmy08:08:58

@iku000888 I have tried it but it still evaluates the whole thing

pesterhazy08:08:58

it slows down evaluation? that doesn't seem right

pesterhazy08:08:08

how much code do you have in your comments?

jimmy08:08:20

@pesterhazy it's about 400 lines

pesterhazy08:08:14

don't think that having this amount of code in a #_'ed out block should affect eval performance

jimmy08:08:05

if I don't have those commented code, it only takes ms. If I do, it takes around 7 8 seconds

pesterhazy08:08:21

my guess is there's something else wrong with your file

pesterhazy08:08:27

or repl environment

pesterhazy08:08:37

maybe the editor is slowing things down?

jimmy08:08:49

hmm, i might me :-?

jimmy08:08:14

I run the repl with comint ( as lein repl ) within emacs

jimmy08:08:17

I don't use cider

jimmy08:08:36

Does it cause any problem ?

iku00088809:08:17

@nxqd Sorry, I think I misread your problem,,,

jimmy09:08:42

np I will try cider if it does solve the problem. hmm there is some problem regarding deps while installing cider, I guess I will try this later then.

onetom11:08:37

@nxqd: sounds like there is something outside of your comment expression. maybe you have multiple comment expressions and something in-between them

jimmy12:08:11

@onetom not really, there is nearly nothing between those. I try to evaluate the the region without comment, it takes ms.

robert-stuttaford13:08:58

super enjoyed the latest episode @vijaykiran @raymcdermott

krchia16:08:25

i am reading through some source code and i am not sure what is the point of defmap

krchia16:08:26

(defmacro defmap [name f & b] "apply a function on all of it's arguments?" `(def name (fn f ~@b)))

seancorfield17:08:23

Given that docstring doesn’t seem right, I’m not sure what to make of that… I mean it seems to be just another form of defn …?

seancorfield17:08:01

(defmap foo [a b c] (println a b c) (+ a b c)) => (def foo (clojure.core/fn [a b c] (println a b c) (+ a b c)))

seancorfield17:08:13

It certainly doesn’t do what the docstring says

seancorfield17:08:36

(and the docstring is in the wrong place)

fellshard17:08:26

Maybe a link to where that's found in the source would help 🙂

abolduc19:08:31

Hey guys, I have a question for you, I am injecting some services to my web application. I would like to destruct these services only once and define my routes after so I came up with something like that :

abolduc19:08:25

The let function only returns the last element of the sequence. is there another method such as let that will return every element of the sequence ?

chrisjd19:08:26

@abolduc You can combine routes with (routes …)

abolduc19:08:01

what do you mean by combine routes ?

abolduc19:08:48

oh god, thats nice

chrisjd19:08:27

No problem. 🙂 If you (macroexpand-1 '(defroutes foo (GET “/“ [] “bar”))) you’ll see that’s all defroutes really is underneath, too.

richiardiandrea20:08:04

so I am playing with spec and I thought of doing:

(def event-fields [::type ::timestamp ::payload])
(s/def ::event (s/keys :req event-fields))
but I have a java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol

richiardiandrea20:08:07

I am in alpha10 (cannot updgrade because of a dependency not updated from the dreaded ns error) so maybe it has been solved...has anybody faced this problem?

jcsims20:08:14

@richiardiandrea: event-fields should be in a seq, I believe

jcsims20:08:31

e.g. (s/def ::event (s/keys :req [event-fields]))

jcsims20:08:52

it’s looking for a seq, finds a symbol instead

richiardiandrea20:08:35

mmm...ok, I am trying, but event-fields is a vector itself

jcsims20:08:10

right - the “args” to the :req key need to be a seq, as you can have many required keys - let me find a link

jcsims20:08:04

oh, I see what you mean now - I read too quickly

richiardiandrea20:08:38

your option works, but I am trying now to see what it validates

Chris O’Donnell20:08:42

I think the problem is that keys is implemented as a macro; it doesn't evaluate its arguments. So you have to pass it sequences, not symbols that evaluate to sequences.

richiardiandrea20:08:52

yes I was suspecting that

richiardiandrea20:08:31

ok, good to know, I was trying to refactor the spec as in plumatic.schema

richiardiandrea20:08:48

where schemas are data and you can play that trick

richiardiandrea20:08:39

and this is especially useful in order to avoid duplication if you are using a http://clojure.org/guides/spec#_multi_spec

abolduc21:08:54

I am stuck with some compojure/jetty problems Id like to parse the body of a POST request to get as json. I use the ring.middleware.json/wrap-json-body tu parse it. if I do : (POST "/" request (-> request (get-in [:body])))) I get the body as a HttpInputOverHttp type. I would like to get a map but nothing seems to work. I use the ring.adapter.jetty as my server.

abolduc21:08:00

any ideas ?

pesterhazy21:08:05

@abolduc, how do you set up the middleware?

abolduc21:08:01

(-> handler (wrap-json-body))

pesterhazy21:08:53

did you restart your repl?

abolduc21:08:40

No should i ?

pesterhazy21:08:55

better safe than sorry!

abolduc21:08:37

I use component to start and stop my jetty server

abolduc21:08:35

I thought I could hot reload my server this way

pesterhazy21:08:03

you probably can, but restart the repl nonetheless, just to be sure

Imad21:08:01

https://github.com/johnwayner/lein-datomic can't run lein datomic start on Windows OS because windows run "bin\transactor" instead of "bin/transactor"

fredmonroe23:08:55

hi is this the right place to ask a clojure question ? ( has to do with reflection of java methods )