Fork me on GitHub
#clojure
<
2015-10-10
>
ghadi00:10:24

tdantas: It's certainly a powerful mechanism you've made. Sometimes scotch is too much and a beer will do. In general highly generic, parameterized code can be hard to maintain

ghadi00:10:27

I kind of loathe reading code where you have to think about what the parameters, which are functions, take

ghadi00:10:39

That aside, I have frequently written a pipeline-esque function, like your chain, but that handles stopping early, rather than running the whole chain. (Usually using loop/recur or reduce/reduced, stopping when the result contains an :error key)

ghadi00:10:15

what you've made is a useful pattern, and seems idiomatic. Just beware over-generifying functions/over-abstracting

jonas08:10:02

I’m using tools.logging and have a log4j.properties file in src/ which writes logs to a file. However, when I run my tests (with lein test) the logs are still written to stdout (and interleaved with the test output). How do I turn off logging when running my tests?

tdantas09:10:47

@ghadi: what do you mean by "I kind of loathe reading code where you have to think about what the parameters, which are functions, take" ?

bensu11:10:42

@oliv: that looks an awful lot like a maybe monad. Take a look: http://clojure.github.io/algo.monads/

tdantas11:10:19

@bensu: thank you for your feedback. how would you do ?

bensu11:10:16

I would put the exception handling in m-result to coerce it to nil and then use the same m-bind

bensu11:10:28

but it might be too much for your case

bensu11:10:42

(middleware in general)

tdantas11:10:02

yeah, so my functions instead of throw exception would handle inside and returns :error in the container.

tdantas11:10:30

ok, let me read your link and try to understand monads

tdantas11:10:55

my understanding about monads ( superficial based on my university class in haskell ) is compose computational steps into multi-step computation

bensu12:10:52

right, handling the steps in between with user defined logic.

bensu12:10:43

you are defining computational steps and you want to stop at any exception, handle it with error-handler and leave

bensu12:10:04

so you can compose your operations with that rule in mind

tdantas12:10:28

> you are defining computational steps and you want to stop at any exception, handle it with error-handler and leave exactly

bensu12:10:31

now you can do more interesting things than just (reverse fn-list)

bensu12:10:57

you can compose them however you like and the pattern will still apply.

tdantas12:10:47

> now you can do more interesting things than just (reverse fn-list) could you exemplify ? ( if i am not bothering you too much )

bensu12:10:10

well, chain is just one example of composing those functions.

bensu12:10:08

that suits your syntactic understanding of middleware (which is totally fine)

bensu12:10:16

if down the road you want to add a conditional between the chaining, where you might have two branches chain doesn't apply anymore

bensu12:10:41

(if auth? auth-middleware-chain non-auth-middlware-chain)

bensu12:10:39

this can be awkward to write using chain (it can, but it won't visually/syntactically reflect your intent)

tdantas12:10:12

>if down the road you want to add a conditional between the chaining, where you might have two branches chain doesn't apply anymore yeah, got it

bensu12:10:36

my hunch is that using a monad that captures the rule you mentioned above you can write that code and get your syntax and intent aligned

tdantas12:10:37

so, how to handle branching situations

tdantas12:10:22

let me remember about the monads and I come back later 😄

tdantas12:10:32

but I got your point

bensu12:10:41

sure I'm not an expert either, good luck simple_smile

tdantas12:10:18

simple_smile thank you, come back later and ping you simple_smile

shriphani23:10:48

hi, a question about the quasiquote. why does args end up as user/args`. But args# ends up as arg__1179__auto__` . I don’t even know what to google for to figure this out.

shriphani23:10:50

this is in the context of a macro I was working on.

andnils23:10:50

@shriphani: google for gensym

shriphani23:10:37

ah so # is gensym ?

shriphani23:10:31

and differs from ’` in behavior? This is quite unexpected (I’ve written macros in racket before).

andnils23:10:32

@shriphani: as you noticed, the back-tick will namespacify your symbol - that won’t happen with apostrophe

shriphani23:10:53

yeah any rationale for this behavior ?

nberger23:10:47

the back-tick ` is syntax-quote. Now you can google it 😛

nberger23:10:30

You'll find useful info under syntax-quote in http://clojure.org/reader. The rationale for it comes the concept of "hygienic macros", and this post explains it very well: https://xivilization.net/~marek/blog/2013/09/17/clojure-and-hygienic-macros/

nberger23:10:50

Extracted from that post: > the problem that Lisp macros usually have, they capture the scope of the point where they were called (think dynamic scoping), not where they were defined (think lexical scoping). Various Lisps have solved this problem in different ways, you can find a lot about this on the internet. Clojure has a somewhat unique solution: syntax-quote does not only quote things, it also adds the namespace to things

raspasov23:10:57

hey everyone - what's the state of affairs about Clojure tree-shaking, I recall Rich Hickey or someone else tweeting that some progress has been done but can't find the old link