Fork me on GitHub
#clojure
<
2018-03-08
>
kenrestivo00:03:57

pretty sure httpkit can do it

pooboy09:03:00

user=> (.(Random.)nextInt(100)) ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval150 (NO_SOURCE_FILE:4)

pooboy09:03:39

I'm trying to use the Random class from Java

pooboy09:03:47

But I'm getting the above error

pooboy09:03:18

I have done (import java.util.Random)

pooboy09:03:44

Guys.. Got the answer

rauh09:03:09

@suryapjr There is also a beginners channel.

pooboy09:03:39

Yea.. Sorry

pooboy09:03:47

Was in a hurry

pooboy11:03:17

Guys..clojure is interpreted?

bronsa11:03:22

it’s JIT compiled

pooboy12:03:57

just in time compiled ?

pooboy12:03:41

so its fast enough for GUI's ,rught ?

matan13:03:41

Hope this is a legit question on this channel, I wonder what would be the state-of-the-art web server library to use in clojure, for a not-very-complicated small web application? in simple, I mean not too many pages or views belonging in the web application, and no huge traffic. Quite a devops oriented web application...

manutter5113:03:27

@matan A lot of people start with luminus — it’s a quick way to pull in a lot of standard libraries and get a server up and running with minimal fuss. http://www.luminusweb.net/

jeff.terrell13:03:41

If it's fairly basic, I might skip Luminus and do more of a bare-bones ring handler function with some ring middleware, with hiccup to create html from data.

jmckitrick14:03:12

I’m doing something similar, but more of an API server. Looking at yada, compojure-api, and others. Thoughts?

tengstrand14:03:56

I’m interpreting that as you @alexmiller didn’t like it! 🙂

matan15:03:00

@alexmiller I probably didn't get it ....

Alex Miller (Clojure team)14:03:47

I think it’s highly unlikely that Rich would like it :)

bronsa14:03:38

esp because :or in e.g. destructuring and or have different semantics

bronsa14:03:57

this would introduce a third

jeff.terrell14:03:33

@teng - Do you know about fnil?

matan15:03:44

on the simple server topic, did any of the revolutionary ones (that like should have been what datomic is to data) end up very usable and stable? I think there was a project om.next going, which was somewhere between odd and experimental at the time

tengstrand15:03:06

@jeff.terrell Thanks for the tip. The alternative was to introduce a let-statement, because the incoming parameter was used in several places in the code and I didn’t want to introduce code duplication by using the ‘or’ or ‘fnil’ function. Clojure supports destructuring in the parameter list for maps that also supports :or, my idea was to support the :or part even for other types than maps.

mbjarland16:03:11

Is there some better (as in more idiomatic and/or faster) way in clojure to get the file line/col of the calling function (when in a function) than traversing (.getStackTrace (Thread/currentThread)) or (.getStackTrace (Throwable. ))?

dominicm17:03:28

Is there something, which can be dereffed to get the current value. Where the current value is updated by a periodic call. I kind of want a (sliding-buffer 1) that's dereffable.

ghadi17:03:22

an atom with a background thread that swaps it?

dominicm17:03:44

@ghadi For my case, the contention would potentially be prohibitive. There could be a lot of updates in bursts.

dominicm17:03:34

My initial thought was an agent, but the lack of backpressure is meh.

noisesmith17:03:37

agents handle contention by queueing instead of retrying, which might be worth it if your retries are expensive

leonoel17:03:42

how could a single writer produce contention ?

dominicm17:03:35

@leonoel that's a good point. I was thinking about that wrong. swap! is sync isn't it?

leonoel17:03:19

yes, but in your case you likely want a dumb reset!

leonoel17:03:33

or a volatile!

dominicm17:03:36

Well, I'm doing step calculations, so it's a good fit for swap!

ghadi17:03:29

sliding-buffer takes values, whereas what you are describing is an update function

leonoel17:03:42

if you can ensure a single writer, you don't need more than volatile

noisesmith17:03:38

how would atom / swap! apply any backpressure btw?

noisesmith17:03:52

if backpressure is a problem you probably want a proper queue or channel setup

dominicm17:03:13

@noisesmith it doesn't, other than that the thing consuming the queue to perform the swap! has backpressure.

dominicm17:03:23

I have a channel setup, don't worry.

noisesmith17:03:43

OK but I don't see how any of this leads to an agent being a problem

rauh17:03:51

TDEPS: Is there an easy way to add a dir to the classpath? Without deps.edn but on the command line.

dominicm17:03:21

@rauh not in tdeps, you could port the add-classpath! function from pomegranate, or use dynapath

dominicm17:03:41

@noisesmith Because if I am consuming from a queue, and immediately sending it to an agent faster than the agent can consume that queue, that will fill memory.

noisesmith17:03:15

and atom/swap! doesn't have this problem? I'm not picturing this

dominicm17:03:50

@noisesmith swap! is sync, so the thing consuming the queue in the first place is blocked until the swap! is complete. send-off is async.

noisesmith17:03:30

oh, right, so it's about keeping the backpressure on the queue you consume from, I get it

ghadi17:03:12

what kind of queue?

dominicm17:03:28

@ghadi I'm using manifold. The queue is handed to me. (But in practice I'm only using manifold.stream/stream for now).

rauh17:03:05

@dominicm Turns out {:paths ["foo/bar"]} works fine for adding to the CP on the command line

dominicm18:03:56

@rauh I totally misread, and thought you were trying to do it dynamically.

dnaeon18:03:13

Hey Clojurians! I've posted this on the #clojure channel on Freenode, but posting here as well in case someone has some ideas about my question. I've started playing out with Compojure and built a simple API, and was wondering how would I go if I wanted to create new clojure.spec's dynamically by simply POST'ing for example some payload to my API endpoint? How would I serialize the spec, so that the API knows how to build a spec out of it? Is this something feasible to do? The idea is to allow users to create new clojure.spec's on demand.

dominicm18:03:44

@dnaeon specs are code, so technically load-file is the best you can do.

dominicm18:03:12

Or load-string even.

dnaeon18:03:03

@dominicm that would be ideal I guess, but the end goal would be to allow non-dev users create specs. Having an API that can create specs and a nice frontend is what I'm thinking about. The users should not really know and care that behind all this is a clojure.spec.

dnaeon18:03:47

Does this sound even reasonable to try implement? 🙂

dominicm19:03:20

@dnaeon so you're looking for a front-end which makes it easy for non-developers to build specs?

dnaeon19:03:53

It would be great if the users were able to write the specs, but they are not really developers, thus the need for a frontend which makes this simple for them.

dnaeon19:03:40

The hardest part I guess would be to provide a frontend which covers all that clojure.spec provides in a nice and intuitive way to use.

dominicm19:03:41

@dnaeon It may be easier to build something that's more constrained to your domain.

dominicm19:03:04

Then have a general-purpose predicate which takes 2 inputs, the DSL & the input to validate against.

pfeodrippe19:03:31

Has someone worked with AWS Lambda? I'm trying to read a file from the resources folder and it's not finding, I'm using serverless for packaging

noisesmith19:03:22

@pfeodrippe the most common error here is that you use io/file or java.util.File to open it - if it's in your resources, it will be inside your jar at runtime, which means you should use http://clojure.java.io/resource to access the contents

noisesmith19:03:48

or you can extract the jar to disk, but you probably don't want to do that in lambda, even if you could

pfeodrippe19:03:41

@noisesmith Thank you, noisesmith, gonna try it, and yes, I'm using clj-pdf and it must use io/file, gonna try your way o/

pfeodrippe19:03:39

It's working, thank you 😃

roklenarcic20:03:58

What's a good shorthand for (when (pred? (expensive-call)) (expensive-call))

roklenarcic20:03:19

basically a single element filter

roklenarcic20:03:27

but I don't want to calculate things twice

roklenarcic20:03:24

when-let and if-let don't cut it because they bind the result of predicate

roklenarcic20:03:44

which is true but not the value being tested

zylox20:03:11

oh shoot ya

roklenarcic20:03:04

a couple of these functions don't play nice with predicates that return booleans

zylox20:03:13

i guess just wrap with a let to store the expensive call

roklenarcic20:03:27

isn't that useful for "find an element that satisfies predicate x" when predicate returns a boolean

zylox20:03:25

(let [x (expensive-call)] (when (pred? x) x))

the2bears20:03:47

edit: oops, focus of the cursor. At least it wasn't a password 😛

roklenarcic20:03:48

yeah, well I was looking for something shorter

petr.mensik20:03:18

Hello guys, any idea how to setup working Sentry appender for Timbre logging (from 3rd party appenders)? I have a configuration like

{:level :info
 :ns-blacklist ["com.mchange.*"] ;disable Korma DB pool logging
 :appenders {:spit (rotor-appender {:path "mylog.log"
                                    :backlog 10})
             :sentry (sentry-appender {:dns "url"})}}
Spit appender is correctly logging to a file (and rotating it), however Sentry logger is not doing anything and I am not sure how test it 🙂 It internally calls raven-clj,core/capture which works well in the REPL by itself so maybe I am not getting the integration correctly or I have some silly mistake there 🙂 Thanks for any hints if you have experience with that 🙂

the-kenny21:03:17

Ohhh, is this nifty metadata handled by Emacs?

ajs21:03:22

When I get an error like this at the repl, is there any way to find out what line number in the source file caused it? ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158)

noisesmith21:03:20

@ajs clojure.repl/pst will show the last stack trace nicely if you call it

noisesmith21:03:43

there's also the value *e which always holds the most recent uncaught exception, including its stack

ajs22:03:32

perfect, thanks