Fork me on GitHub
#clojure
<
2017-10-03
>
kaosko02:10:03

argh. why is my mixed java/clj trying to first compile clj that is dependent on the java classes? even if I run lein javac, it tries to compile clj

noisesmith02:10:12

often the simplest thing is to never compile your clj - to just put sources in your jar since you can't run clojure without the compiler anyway

kaosko02:10:34

okay @noisesmith - how do I tell leiningen not compile my clj?

noisesmith02:10:55

by not having an :aot key in your project.clj

kaosko02:10:33

I don't, I only have it in uberjar profile. but I don't know, I feel this should be very simple. my java doesn't refer to any clj classes, it's strictly a library, yet leining wants to compile clj first, even on "lein javac"

noisesmith02:10:15

it shouldn't be compiling anything if you don't specify aot

kaosko02:10:57

my thoughts exactly

noisesmith02:10:04

there's gen-class but it shouldn't even get that far

noisesmith02:10:47

do you have a prep task of some sort that needs to load your namespaces?

noisesmith02:10:07

clojure doesn't have a "compile only" mode, so if anything needs to load your namespaces, the classes they use must exist

noisesmith02:10:41

which could include prep tasks or things like lein check or lein eastwood

kaosko02:10:14

right.. wonder if it could be a plugin but don't use many

noisesmith02:10:35

the stack trace when it complains about the class not existing might be informative

kaosko02:10:25

not to me but: at myclj.core$eval27078.invoke(core.clj:1) at clojure.lang.Compiler.eval(Compiler.java:6927) at clojure.lang.Compiler.eval(Compiler.java:6916) at clojure.lang.Compiler.load(Compiler.java:7379) at clojure.lang.RT.loadResourceScript(RT.java:372) at clojure.lang.RT.loadResourceScript(RT.java:363) at clojure.lang.RT.load(RT.java:453) at clojure.lang.RT.load(RT.java:419) at clojure.core$load$fn__5677.invoke(core.clj:5893) at clojure.core$load.invokeStatic(core.clj:5892) at clojure.core$load.doInvoke(core.clj:5876) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.core$load_one.invokeStatic(core.clj:5697) at clojure.core$load_one.invoke(core.clj:5692) at clojure.core$load_lib$fn__5626.invoke(core.clj:5737) at clojure.core$load_lib.invokeStatic(core.clj:5736) at clojure.core$load_lib.doInvoke(core.clj:5717) at clojure.lang.RestFn.applyTo(RestFn.java:142) at clojure.core$apply.invokeStatic(core.clj:648) at clojure.core$load_libs.invokeStatic(core.clj:5774) at clojure.core$load_libs.doInvoke(core.clj:5758) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invokeStatic(core.clj:648) at clojure.core$require.invokeStatic(core.clj:5796) at clojure.core$require.doInvoke(core.clj:5796) at clojure.lang.RestFn.invoke(RestFn.java:436) at user$eval3$loading__5569__auto____4.invoke(user.clj:1) at user$eval3.invokeStatic(user.clj:1) at user$eval3.invoke(user.clj:1) at clojure.lang.Compiler.eval(Compiler.java:6927)

kaosko02:10:36

this is from running lein javac

noisesmith02:10:04

why is it loading your user.clj ?

noisesmith02:10:40

I mean, I can guess why lein would do that, but I am now suspicious about what user.clj is doing

Alex Miller (Clojure team)02:10:57

The Clojure runtime always loads user.clj on initialization

seancorfield04:10:25

Worth mentioning that is essentially "untrue" with Boot (Clojure attempts to load user.clj but won't find it anywhere useful).

kaosko02:10:22

oh thought I didn't have user.clj but I do. this is from a Luminus template.. it's mounting the repl-server.. and I guess together with https://github.com/technomancy/leiningen/issues/1245 causes the issue

noisesmith02:10:43

yeah, I was unclear in my statement, I meant "your user.clj is the reason this is breaking"

kaosko02:10:09

yeah that's it thanks @noisesmith!

noisesmith02:10:01

you can probably see how I deduced that from your stack trace 😄

kaosko02:10:34

🙂 sure. I didn't know about the whole user.clj or the problem with it & javac. thanks again!

noisesmith02:10:03

well, the issue we were looking for was why your clj namespaces were being loaded before running javac, the fact that user.clj is mentioned at the "top" of the stack trace tells me that it is the culprit

seancorfield04:10:25

Worth mentioning that is essentially "untrue" with Boot (Clojure attempts to load user.clj but won't find it anywhere useful).

qqq06:10:30

are there any recent libs for pulling stock data from google/yahoo ? I've found 3 libraries so far, they're all 7+ years old, and I'm pretty sure the API has changed since then

yogidevbear10:10:31

@U04V15CAJ, I ordered a copy on Sunday evening. Should arrive some time today. I believe the author is @U051GTC61, but not certain

yogidevbear10:10:40

I was hoping to get some feedback from anyone else that had ordered the book before (I think it's a September '17 release), but no one replied to my comments a few days back.

raspasov09:10:21

Question for all: which do you prefer and why? (:my-key my-map)

raspasov09:10:41

(get my-map :my-key)

schmee09:10:40

I usually use (:keyword m) if the map uses keywords as keys, and (get m thing) for everything else

raspasov09:10:44

(assuming :my-key is a keyword in-line and not dynamically resolved in which case there’s a chance it can be nil or something non-callable)

kwladyka10:10:28

What do you think about http://www.onyxplatform.org ? Just to know, do we have another alternatives? At that moment team needs mainly get data from one DB and put to others in different formats.

razum2um10:10:43

@kwladyka it’s readme mentiones http://storm.apache.org/ - the latter is proven, stable, but seems to be not such actively developed

kwladyka10:10:31

yes, first impression is better about onyx 🙂

schmee10:10:55

AFAIK, Storm has been superseded by https://twitter.github.io/heron/ at Twitter

schmee10:10:29

I haven’t had the time to try out Onyx unfortunately, but it does look pretty sweet

mpenet10:10:33

if you just need to fan out maybe you dont need any of these

schmee10:10:01

@kwladyka what DB are you using?

kwladyka10:10:34

The source is API and we need to put it into elastic and postgresql

kwladyka10:10:54

yeah, but writing ourself logic about what to do when something fail, write everywhere try and catch only to send errors to sentry (logger) etc. What i know onyx has this logic already implemented.

kwladyka10:10:36

But didn’t use it

mccraigmccraig10:10:59

@kwladyka we've been using onyx to process events out of kafka for a while and had mostly happy times

kwladyka10:10:05

thx all, we will just probably try it 🙂

cddr10:10:06

This is one of the use-cases that confluent are pimping Kafka for. It would be pretty simple. You'd write a kafka-connect source connector to get your API data into kafka, maybe add some transformations to get it structured correctly for your target database, then a kafka-connect sink would load it into postgres

cddr10:10:05

The multiple sinks requirement is solved quite elegantly with this approach. Just have separate processes consume the source topic and write out to their sink topic.

misha11:10:48

@raspasov (:key m) avoids nullpointers in m

raspasov11:10:34

@misha yes… what do you mean exactly? 🙂

raspasov11:10:35

(get m :key) also avoids… (but not as concise)

misha11:10:38

(let [m nil] (:key m))
=> nil
(let [m nil] (get m :key))
=> nil
(let [m nil] (m :key))
java.lang.NullPointerException

raspasov11:10:06

ahh yes 🙂 I never do (m :key) for that reason

raspasov11:10:37

also dangerous is (my-key m)

raspasov11:10:06

unless you’re 100% sure my-key will always end up being a keyword

misha11:10:14

and get is wordy :) I usually use ->, which is basically (:key m)

raspasov11:10:36

yes… I agree

misha11:10:45

(-> m :foo :bar)

raspasov11:10:06

the one useful feature of (get …) is (get m :key :not-found)

raspasov11:10:26

(if you’re interested in knowing whether it was found or the value was nil)

mgrbyte11:10:00

can also say (:key {} :was-not-found)

raspasov11:10:19

didn’t know that!

misha11:10:27

but majority of my usecases: ui templates, where I am 99% sure key is keyword, and m is 90% dynamic. however I always use get if I supply default value, because default value for (:key m default) is "unusual", and (get m :key default) feels more explicit to me

mgrbyte11:10:11

whatever communicates intent best :thumbsup:

raspasov11:10:37

@mgrbyte damn that’s cool! haha always enjoy learning new things about Clojure, even after a bunch of years using it now…

raspasov11:10:55

on a somewhat separate point, perhaps a less known thing about Clojure is (nth [] 1 :not-found)

misha11:10:17

also default value for :key does not "play well" with threading macros -> and ->>

raspasov11:10:26

… which also avoid exceptions (just adding here if useful for someone)

raspasov11:10:20

for that reason I don’t use the threading macros that much… sometimes it just becomes cumbersome to “thread it through the right place” lol

sundarj11:10:01

i think that's what as-> is for 🙂

raspasov11:10:54

but (some-> …) I enjoy a lot 🙂

misha11:10:21

I mean: for just keys you can do both -> and ->>, and change macro "at will", say you started with (-> m :foo :bar), but then you need to add map, so you do (->> m :foo :bar (map inc))

raspasov11:10:48

@misha mmm yes… I would probably do this one like (into [] (comp (map :foo) (map :bar) (map inc)) [m]) … I abuse transducers a lot lol

misha11:10:17

but you can't switch from -> to ->> willy-nilly with (:foo default). and for some reason, I think (get :key default) makes it more obvious that you "stuck with" ->

misha11:10:25

your code is ... not obvious )

misha11:10:34

(let [m {:a {:b [0 1]}}] (->> m :a :b (map inc)))
=> (1 2)
(let [m {:a {:b [0 1]}}] (into [] (comp (map :foo) (map :bar) (map inc)) [m]))
java.lang.NullPointerException: 

misha11:10:53

@raspasov also there is as->, for when you need to thread through random argument positions

(as-> [1 2] $
  (conj $ 3)
  (map inc $))  
=> (2 3 4)

raspasov11:10:01

@misha yes… 🙂 I do know that one, somehow I never made big use of it, maybe I should

raspasov11:10:13

perhaps because it’s a macro with “a lot of syntax” (relatively speaking) and my brain has generally become allergic to most syntax lol

raspasov11:10:03

but it is quite elegant if used properly

misha11:10:24

yeah, way too much syntax, like specifying all of the function's arguments, who does that anyway! kappa

misha11:10:14

competing with -> is hard though

ttx12:10:19

Is there any agreed upon convention for naming of binding of atoms and refs?

raspasov12:10:55

@ttx do you mean like (defonce my-atom (atom {})

misha13:10:58

"recommend" for what?

mpenet13:10:58

indeed, it's not clear to what purpose

misha13:10:47

I heard datomic is good kappa

Jon13:10:06

...to show how FP works in real-world projects, I guess

mpenet13:10:11

no source access, if it's to learn the language that sucks 🙂

leonoel14:10:39

hi, anyone knows if any attempts have ever been made to standardize lazy, callback-style asynchronous computations ?

leonoel14:10:31

anyways, if anyone is willing to contribute to this effort, feel free to DM me

genec14:10:56

@jiyinyiyong Clojure is a good example of a mainstream project written in Clojure 💥

Jon14:10:52

good point~

sundarj14:10:35

@jiyinyiyong CircleCI's frontend is in cljs and on github

leonoel14:10:31

anyways, if anyone is willing to contribute to this effort, feel free to DM me

acron14:10:26

Trying to get my head around some macro basics. Is it possible for me to provide a symbol and have that resolved inside the macro so that I can do something like this? (my-macro my-vector) => #{:a :b :c} (contrived example)

Alex Miller (Clojure team)14:10:35

user=> (def my-vector [:a :b :c])
#'user/my-vector
user=> (defmacro my-macro [v] `(set ~v))
#'user/my-macro
user=> (my-macro my-vector)
#{:c :b :a}

acron14:10:24

@alexmiller Thanks, I think the macroexpand was confusing me

Alex Miller (Clojure team)15:10:26

just always keep in mind that macros are code -> code functions

Alex Miller (Clojure team)15:10:41

user=> (macroexpand '(my-macro my-vector))
(clojure.core/set my-vector)

Alex Miller (Clojure team)15:10:18

so my-vector is not resolved “inside” the macro, rather it is part of the rewritten code emitted by the macro (and later evaluated)

tdavis15:10:12

anybody know how to use spec on a multi-arity function? such as (defn x ([] (x 1)) ([n] n))? i can spec the one with args easily enough but not sure how to let :args know it's cool if there is no argument.

Alex Miller (Clojure team)15:10:05

(s/fdef x :args (s/? :n any?))

tdavis15:10:32

hmm, getting "wrong numbers of args to ?" looks like it wants pred-form

Alex Miller (Clojure team)15:10:04

(s/fdef x :args (s/? any?))

Alex Miller (Clojure team)15:10:21

if you want better doc’ed conformed args, could also do:

Alex Miller (Clojure team)15:10:32

(s/fdef x :args (s/cat :n (s/? any?)))

tdavis15:10:09

ah, ok, i was about to ask. i'm getting another issue i think because i have them in the wrong order (`s/cat in s/?`)

Alex Miller (Clojure team)15:10:47

seems like would also possibly work?

Alex Miller (Clojure team)15:10:59

(s/fdef x :args (s/? (s/cat :n any?))) ?

Alex Miller (Clojure team)15:10:12

s/? is a little strange when used at top level

tdavis15:10:32

both orderings result in Boolean cannot be cast to IFn

Alex Miller (Clojure team)15:10:00

can you list a full repro?

Alex Miller (Clojure team)15:10:42

no, s/or takes specs (including predicates as specs)

Alex Miller (Clojure team)15:10:50

spec names like that are fine

Alex Miller (Clojure team)15:10:27

don’t see anything wrong there

Alex Miller (Clojure team)15:10:41

what do you evaluate when you get the error?

tdavis15:10:03

(connect!)

Alex Miller (Clojure team)15:10:54

well that doesn’t do anything with spec

Alex Miller (Clojure team)15:10:12

unless you’ve instrumented or are invoking spec inside connect!

tdavis15:10:26

oh, sure, i have called instrument

Alex Miller (Clojure team)15:10:43

the parts you’ve shown look fine to me. what’s in ::client and ::client-spec?

tdavis15:10:32

::client is an inst? spec and ::client-spec is a keys spec. they work fine outside the function context.

Alex Miller (Clojure team)15:10:53

have you re-invoked instrument after modifying the specs?

tdavis15:10:57

yep, the returned vector included connect!

borkdude15:10:09

I absolutely love this clojure linting tool (can use it in conjunction with several editors): https://github.com/candid82/joker

Alex Miller (Clojure team)15:10:23

@tdavis I built a subset in local repl and couldn’t reproduce

Alex Miller (Clojure team)15:10:43

so either I’m missing something or your repl has out of date state

tdavis15:10:02

how odd. it definitely goes away if i get rid of the s/?. i will restart repl and try again.

tdavis15:10:12

thanks for the help!

ghadi15:10:16

@tdavis there are 2 issues with s/?, grabbing you the links...

ghadi15:10:32

Probably the first one (2105)

ghadi15:10:26

If you have a reproduction case that looks different, please help out by pasting it on the jira! (can put code blocks like {code} .... {code})

iarebatman16:10:50

Does anyone have a few minutes to help me out with a HugSQL issue I'm experiencing?

iarebatman16:10:56

I have a postgres table with 2 timestamptz fields that allows NULLs. On the hugsql side, one of the fields maps to basically {:timestamp_1 ...} while the other one maps to {:sub {:timestamp_2}} :timestamp_1 properly inserts a NULL, but :timestamp_2 throws a Parameter Mismatch exception (parameter data not found). I'm accessing timestamp_1 via :timestamp_1 in my .sql file, and timestamp_2 via :sub.timestamp_2 - so I don't believe it's a simple mistake on my part - as I'm doing this for other field types just fine

iarebatman16:10:29

I have verified that the map being passed to the hugsql-generated function has the keys for both fields and their values are nil

iarebatman16:10:32

...wrong window, sorry.

yury.solovyov18:10:29

@jiyinyiyong Wire IM has server-side stuff written in Haskell https://github.com/wireapp/wire-server

markbastian18:10:30

is the correct way to reference a project value in maven to simply key off of project (e.g. (:jar-filename project))?

markbastian18:10:39

err, lein, not maven

waffletower19:10:06

@misha have you used as-> when you have mixed arities?

hlship22:10:15

Anyone using Apache Spark, sparkling, and the Datastax Cassandra Driver all together ... looking to share insights/misery.

cfleming23:10:08

I’m going a bit nuts here - I want to generate a form using quasiquoting, which includes a non-namespaced quoted symbol. I’m trying to generate code which calls intern.

cfleming23:10:35

`(intern 'clojure.core 'test true)
=> (clojure.core/intern (quote clojure.core) (quote clojure.core/test) true)
`(intern 'clojure.core 'test.foo true)
=> (clojure.core/intern (quote clojure.core) (quote test.foo) true)
`(intern 'clojure.core ~'test true)
=> (clojure.core/intern (quote clojure.core) test true)
`(intern 'clojure.core (quote test) true)
=> (clojure.core/intern (quote clojure.core) (quote clojure.core/test) true)

cfleming23:10:12

So quasiquoting only namespace qualifies symbols which don’t contain dots?

cfleming23:10:34

How can I get the test symbol unqualified in the output?

bfabry23:10:49

boot.user=> `(intern ~'test)
(clojure.core/intern test)
boot.user=>

bfabry23:10:52

gah, beat me

bfabry23:10:20

seems like you actually got it for one instance

cfleming23:10:23

@bfabry It actually requires the extra quote too, otherwise it’s not quoted in the output.

cfleming23:10:46

@hiredman Thanks - that would have taken me a while.