Fork me on GitHub
#clojure
<
2016-10-06
>
yonatanel12:10:46

Is there anything like core.async or manifold but with the addition of consumer having to acknowledge when it's done processing a message? A stream/channel that behaves more like Kafka, amazon's SQS or anything with at-least-once semantics.

misha14:10:34

@yonatanel do you mean, producer would get notified when consumer finishes (as opposed to "starts") processing of a single value?

yonatanel14:10:21

@misha yes, because if I'm consuming Kafka into a buffered channel I might commit the offset too early, before that buffer was actually processed.

misha14:10:57

can you make those steps linear? as in:

A-->B-->C
instead of circular
AC<-->B

yonatanel14:10:20

of course, if that's the desired model. I just wonder if anyone modeled it in memory

yonatanel14:10:19

I've seen people pass a promise together with the message, and resolve the promise when done processing, but it's ugly

dm315:10:47

you can have a bidirectional stream where you ack each message

dm315:10:33

I'd probably go with a separate API for acks

richiardiandrea20:10:04

Hello folks, I was wondering, is there a way to pretty print log error messages (an ex-info data for instance), kind of like what Ruby does with https://github.com/smartinez87/exception_notification ?

Paco20:10:05

there is nothing special in exception_notification. Nothing you could not roll out in an hour or two with no dependencies.

Paco20:10:05

I guess it depends what you need. If you are working on a ring you could do something like https://8thlight.com/blog/mike-knepper/2015/05/19/handling-exceptions-with-middleware-in-clojure.html

poverholt21:10:44

Using Java Interop, how do I write to a public instance field? http://Clojure.org reference has the example (.-x (java.awt.Point. 1 2)) for reading. How would I write the x field to be 3 for example?

bfabry21:10:22

@poverholt (set! (. instance-expr instanceFieldName-symbol) expr)

richiardiandrea21:10:18

@kidpollo thanks for the link..the comparison went there, and of course that lib has more than 500 commits so it must be doing something ;) I hope your estimate is good and I'll have to work just a few hours on it

borkdude21:10:42

I don’t get this macroexpansion (from a boot REPL):

boot.user=> (macroexpand `(fn [] {:post [(even? %)]} 1))
(fn* ([] (clojure.core/let [% 1] (clojure.core/assert (clojure.core/even? boot.user/%)) %)))
The assert works, but why boot.user/%?

jr21:10:50

syntax quote will always try to expand symbols

jr21:10:57

use ’% if you don’t want it qualified

bfabry21:10:03

that is the reason yes. I think the underlying issue is you forgot the # on your function literal though.

boot.user=> `(fn[] {:post [#(even? %)]} 1)
(clojure.core/fn [] {:post [(fn* [p1__2437__2438__auto__] (clojure.core/even? p1__2437__2438__auto__))]} 1)

borkdude21:10:32

@bfabry post conditions don’t expect a function literal

jr22:10:18

why not just reference the even? function?

jr22:10:32

it’s a unary function

richiardiandrea22:10:44

@borkdude not familiar with the fn expansion, but usually you use a ' with macroexpand

borkdude22:10:16

@jr that’s also not how post conditions work. you have to provide an expression that references %

richiardiandrea22:10:30

(at least I don't think you need to qualify the symbols there)

bfabry22:10:58

@borkdude function literals don't support post conditions anyway, but you're right

borkdude22:10:12

note that the code does what I want, it’s just the macroexpansion that looks weird.

borkdude22:10:32

@bfabry that’s also untrue

hiredman22:10:36

user=> (fn[] {:post [(#(even? %) %)]} 1)
#object[user$eval30$fn__31 0x130dca52 "user$eval30$fn__31@130dca52"]
user=> (*1)
AssertionError Assert failed: ((fn* [p1__29#] (even? p1__29#)) %)  user/eval30/fn--31 (NO_SOURCE_FILE:9)
user=> 

borkdude22:10:37

((fn [] {:post [(even? %)]} 1))

java.lang.AssertionError: Assert failed: (even? %)

hiredman22:10:39

works just fine

bfabry22:10:51

well that's surprising. it's undocumented

hiredman22:10:45

which part is?

bfabry22:10:54

pre/post condition maps on function literals

hiredman22:10:14

'(fn name? [params* ] condition-map? exprs*)'

hiredman22:10:30

it then explains what can be in condition-map?

bfabry22:10:35

right, well undocumented on clojuredocs http://clojuredocs.org/clojure.core/fn

hiredman22:10:13

I don't know why people use clojuredocs

bfabry22:10:33

because it's what the http://clojure.org cheat sheet links to

borkdude22:10:56

so (eval (macroexpand-all expr)) is not always equal to evaluating expr from the REPL?

borkdude22:10:18

(eval (macroexpand-all `((fn [] {:post [(even? %)]} 1))))

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such var: boot.user/%, compiling:(/var/folders/7t/gpzjxhts24d5wvqys1dfvrd80000gn/T/boot.user1557650643773325784.clj:1:1)
             java.lang.RuntimeException: No such var: boot.user/%

hiredman22:10:56

definitely not when using syntax quote

hiredman22:10:02

syntax quote is not quote

hiredman22:10:15

it will rewrite parts of your expression

borkdude22:10:32

aaah oops, sorry. I’m only aware I used a backtick instead of quote now

borkdude22:10:38

sorry, I should be sleeping. bye

hiredman22:10:45

the ugh was directed at the cheatsheet

hiredman22:10:54

clojuredocs is largely the blind leading the blind, and should be take with a grain of salt

tomjkidd22:10:48

@borkdude (eval (macroexpand-all `((fn [] {:post [(even? ~'%)]} 1))))

bfabry22:10:52

ok, have you got a better quick reference for clojure than the cheat sheet?

tomjkidd22:10:12

note the ~' (quote, not backtick)

hiredman22:10:13

apropos, doc, a repl, and the source

bfabry22:10:24

I notice this is also true of the autogen'd docs so I don't really see this as clojuredoc's fault http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/fn

tomjkidd22:10:14

as others have mentioned, the reader attempts to resolve % as a fully qualified namespace when using the backtick

borkdude22:10:57

@tomjkidd yeah, thanks, I was just mislead by having ` in my muscle memory

bfabry22:10:47

(doc fn) also doesn't mention condition maps

tomjkidd22:10:52

search for "Since 1.1"

bfabry22:10:10

@tomjkidd I know it's on that particular page

bfabry22:10:29

just not in any of the other clojure documentation sources

tomjkidd22:10:17

Rich Hickey has stated (doc x) is meant to be terse

hiredman22:10:51

user=> (s/describe `fn)
(fspec :args (cat :name (? simple-symbol?) :bs (alt :arity-1 :clojure.core.specs/args+body :arity-n (+ (spec :clojure.core.specs/args+body)))) :ret any? :fn nil)
user=> (s/describe :clojure.core.specs/args+body)
(cat :args :clojure.core.specs/arg-list :prepost (? map?) :body (* any?))
user=> 

hiredman22:10:00

that is kind of neat

borkdude22:10:00

just look at the macro-expansion 😉

borkdude22:10:39

@hiredman yes, it is, innit

tomjkidd22:10:52

(source fn), too, if you are willing...

bfabry22:10:49

jesus, there's terse and then there's missing some of the arguments. it's cool that you can drill down to it in the alpha using spec, but I don't think anyone is very likely to do that

borkdude22:10:39

I’ve done this before when I was wondering about this. I think it’s one of the points of spec, documentation.

hiredman22:10:22

the alpha actually prints out the spec with the doc

borkdude22:10:39

"Problems Docs are not enough” http://clojure.org/about/spec

bfabry22:10:57

it does, but because of the indirection there's not much of a hint that it will accept a prepost map

hiredman22:10:46

I am not sure what your point is

borkdude22:10:48

Because people are too lazy to follow an indirection? 😛

hiredman22:10:57

its documented in the offical docs on http://clojure.org, clojuredocs is a community effort(last I checked) that a lot of people like to use for whatever reason, which has resulted in some references to it creeping in to stuff on http://clojure.org (in specifically community contributed parts like the cheat sheet)

hiredman22:10:40

docstrings are not always comprehensive

bfabry22:10:06

my point was, I went to the reference documentation where most people would look, the http://clojure.org cheat sheet and clicked on fn, and it didn't include prepost map so I figured it didn't. then I got told "ugh, you shouldn't use the cheat sheet" I should use apropos and doc apparently, which also don't mention it, but that's apparently ok because doc is supposed to be terse, and I could've followed 2 levels of spec indirection (if I happened to be using the alpha) to find out what arguments the core freakin form supports

hiredman22:10:49

I also included the source in there with apropos and doc

hiredman22:10:01

the source has a comment right above it about adding pre and post support

borkdude22:10:11

@bfabry tbh I never used pre/post on fn, I just discovered it by luck/trying. It’s not that terribly important.

bfabry22:10:56

@borkdude exactly, unless you've read that specific page or the source recently there's no way you'd know it supported it. I'm pissed at the general attitude that "derr you're doing it wrong" when it's pretty clearly barely documented

hiredman22:10:45

I knew it supported it, but didn't know the comment was until I looked

hiredman22:10:50

I don't think anyone said you were doing anything wrong. I don't care for http://clojuredocs.org

hiredman22:10:29

the objective truth of what is and isn't there, is in the clojure source code (since there is no formal language spec), at a remove from that are the http://clojure.org docs, and at even more removes from that are the clojuredocs docs

tomjkidd22:10:31

Yeah, I think all it was is each of us were thinking about the ways that we would find that information. And the fact that they are so diverse is just something to think about for when you are curious about something else

jrheard22:10:09

@bfabry - you could rectify the situation by adding this information to http://clojuredocs.org/clojure.core/fn , no?

hiredman22:10:33

to walk around complaining about things not being documented is silly too, there are a whole lot of docs, did you read them all? is that how you can say something isn't documented?

jrheard22:10:51

i’ve never used that website to add an example myself, but it looks like that’s something that’s possible, and seems like it would solve the problem you are frustrated with

bfabry22:10:16

and the circle's complete, "make a pr". I am in the process of doing that. I wasn't complaining, I was explaining why I didn't think it was supported, and got annoyed at the "should've read the source" bullshit

hiredman22:10:23

if you really want to know, read the source, if you only sort of kind of want to know, read other stuff

hiredman22:10:11

I am not saying everyone should drop everything and read it or anything

hiredman22:10:36

but if you have a question, what to know how something works, etc the source is there

bfabry22:10:57

please stop telling that to everyone who comes across an incomplete piece of documentation, I quite like clojure and it's hard enough to hire people who know it without having people actively discouraging people from using it

hiredman22:10:57

but my issue is with saying it isn't documented, when it is, just not in the docs you are reading

hiredman22:10:10

I don't tell that to everyone and I haven't

dpsutton22:10:53

its also a great reminder that lisps are implemented mostly in lisp

dpsutton22:10:01

you can read the source most of the time

hiredman22:10:07

Hah, has clojure got a surprise for you 🙂

dpsutton22:10:10

it's almost turtles all the way down

dpsutton22:10:42

you run into java at some point and then you're dealing with classes and compiler stuff