Fork me on GitHub
#beginners
<
2016-09-07
>
abarylko02:09:38

I’m adding logging to a compojure-api app

abarylko02:09:03

What’s the default logger and how can I configure the output format, etc?

abarylko02:09:13

any help will be appreciated 🙂

donaldball02:09:18

The standard api is clojure.tools.logging

donaldball02:09:47

There are more ways to configure it, and more apis competing to replace it, than has any business being the case, alas

donaldball02:09:10

I’ve been using unilog lately to configure it. Declarative, simple, and easy.

cameronbourke05:09:24

Would love if someone in here has some insight into why clojure doesn’t have always have the data last for it’s functions in the core.

cameronbourke05:09:47

For example:

(str/split <data> <regex>)

cameronbourke05:09:30

Which means I cannot partially apply the split function like so:

(def splitByComma (partial str/split #”,”))
(splitByComma “Sentence,with,commas,all,through,it”) // noop

seancorfield06:09:12

@cameronbourke generally Clojure functions that accept collections have the collection as the last argument, but otherwise the "data" argument is going to be the first argument (like OOP 🙂 )

seancorfield06:09:10

(def split-by-comma #(str/split % #","))

seancorfield06:09:32

Note: kebab-case, not headlessCamelCase, is idiomatic in Clojure.

cameronbourke06:09:19

@seancorfield Cool! Is there anywhere that goes into the rationale of doing that?

cameronbourke06:09:35

Also sorry! To used to js haha.

seancorfield06:09:30

Rationale of argument order? Read that blog post and see if it is what you're looking for.

cameronbourke06:09:15

@seancorfield Yeah that is actually really helpful. Espicially But what about partial? Unfortuantely I don’t know clojure well enough to understand this work around: > However again – as Rich's states: #() simply takes care of any problems you might have with partial[2]. #(assoc % :a 1) is even shorter than (a hypothetical) (partial assoc :a 1). [3]

seancorfield06:09:19

As I showed above, #( ... % ... ) let's you write an anonymous function (of one argument) with that argument wherever you want.

cameronbourke06:09:21

@seancorfield That is awesome! So does % become a placeholder? My expectation is that split-by-comma returns a function that only accepts one param being the string in this case.

cameronbourke06:09:25

Is that right?

seancorfield07:09:39

#( ... % ... ) is like (fn [x] ( ... x ... ))

zzamboni07:09:52

@cameronbourke note that you can also have multiple arguments in anonymous functions by using %1, %2, etc., although beyond two args IMO it gets confusing quickly, in those cases I usually switch to regular (fn ...) syntax.

cameronbourke10:09:09

@zzamboni What is it called when calling a function in clojure using #(…) syntax?

zzamboni10:09:39

@cameronbourke Anonymous functions

zzamboni10:09:22

Actually anonymous functions are (fn [...] ...) (i.e. a function declaration without a name), #( ... ) is a reader macro shortcut version for it.

cameronbourke12:09:46

@zzamboni Aw okay, cool! But for the str/split example above, using an anonymous function would not allow you to do #(str/split % #",”). Or would that look like (fn [x] (str/split [x] #”,”))?

zzamboni12:09:11

#(str/split % #",") is correct, the second is almost correct: (fn [x] (str/split x #","))

zzamboni12:09:16

both are equivalent

zzamboni12:09:30

,(macroexpand '#(clojure.string/split % #","))

cameronbourke12:09:07

@zzamboni Sweet, so there is no partial application to the function, it just wraps it with another function which accepts the placeholder value/s

zzamboni12:09:12

if you type this in the repl (without the initial comma) you'll see that it expands to the full syntax

cameronbourke12:09:10

Cool! (fn* [p1__1258#] (clojure.string/split p1__1258# #",”))

zzamboni12:09:44

Didn't we have a bot here that evaluated clojure expressions?

shaun-mahood16:09:58

Does anyone know any good resources for hosting Clojure web services easily (within my local network), particularly without a good understanding of either Linux or Java web servers? In my ideal world it would just be a linux VM or something along those lines that I can just throw a uberjar/uberwar at. I've got things working reasonably well on Windows with Tomcat, but I'd like to get a bit more of a Clojure standard setup for some of the future things I want to do.

tom18:09:18

@shaun-mahood: I've been enjoying using Docker. It's fast and acts similar to a VM. Use docker-compose. For Windows they have a big installer for docker and docker-compose. It's not beginner friendly and on Windows it can act oddly. But once you learn it it's extremely easy to use and powerful.