Fork me on GitHub
#clojure
<
2017-09-11
>
souenzzo02:09:40

How to deliver a exception, like datomic.api/transact?

lfn302:09:09

Not sure what you mean by deliver?

lfn302:09:07

If you mean throw, it's (throw (ex-info "An exception" {:some :data})) or substitute (ex-info ...) for any other exception.

souenzzo02:09:51

Did you use datomic? On datomic, you can (d/transact conn :invalid) and it will return a future. This future will just throw if you try to deref it.

lfn302:09:13

Ok. You could just implement clojure.lang.IDeref which is what future and promise etc implement.

lfn302:09:11

(reify
  IDeref
  (deref [_] (throw (ex-info "bang!" {}))))

souenzzo03:09:28

I need to reify IDeref and IFn (and it works) There is some way to do not need to reimplement IFn?

lfn304:09:34

I don't seem to have that issue

lfn304:09:55

(let [v (reify
          IDeref
          (deref [_] (throw (ex-info "bang!" {}))))]
  @v)
user=> ExceptionInfo bang!  clojure.core/ex-info (core.clj:4744)

souenzzo09:09:07

I'm reifying a promise. Then I have erros when I try to deliver

lfn309:09:45

I’m probably not going to be online for much longer, but if you send that code I’ll let you know if I can spot any issues with it.

didibus06:09:12

QUESTION: Is there a partition-by which has f taking the previous or all already created partitions as well as the next element?

didibus06:09:48

For context, I'm trying to partition every time next element is smaller then previous element

didibus06:09:02

Like this:

(let [prev (atom nil)]
  (partition-by (fn [e]
                  (when (or (nil? @prev)
                            (< e @prev))
                    (reset! prev e)
                    e)) '(9 8 6 3 5 6 7 10)))
But where I don't need to use a mutable atom outside the scope of partition-by ?

hmaurer12:09:42

you might want to read about “stateful transducers”

noisesmith18:09:40

you could also look at the two arg arity of partition-by and modify that so that f takes two args, and partition-by-++ takes an extra arg as well

gfredericks11:09:12

@didibus what do you expect for (8 4 7 6 10)?

gfredericks11:09:36

(that code returns ((8) (4 7 6 10)))

vinai18:09:51

Is there a list of "transducer producing functions" somewhere, like map, filter, keep, remove...? Tried to google but I just get general posts on transducers.

sundarj18:09:46

(find-doc "transducer")

sundarj18:09:05

@noisesmith sorry for the ninja 😁

noisesmith18:09:09

haha no need to apologize, I ninja all the time

sundarj18:09:28

I'm British, apologizing is one of our national sports

sundarj18:09:02

along with queuing and football

noisesmith18:09:14

with a bit of effort you could have phrased that as an apology

sundarj18:09:45

snaps fingers

sundarj18:09:57

you're pretty good at thsi

noisesmith18:09:31

actually I bet the best result would come from transduc which would match transduce transducing transducer etc.

sundarj18:09:19

good point

vinai18:09:18

@alexmiller Oh, thanks, I missed that. I was scanning the page for a list, not a paragraph.

gordon20:09:47

Hey folks, I've used the #= reader macro in the past to evaluate a form at read time (ex: #=(* 24 60)), but I can't find a reference to it in the official docs. Is that something that is missing documentation, or might support for it go away in the future?

bronsa20:09:59

I'd say using it is a very bad idea

bronsa20:09:21

it's not a general purpose read-eval like common lisp's

bronsa20:09:00

I consider it an implementation detail

gordon20:09:52

OK, that makes sense. thank you.

gordon20:09:10

I'm trying to add the result of a simple expression like (str *ns* "/" "some-fn") to metadata that will become a Java annotation, and #= worked for that use case. Do you know of an alternative that would work for that use case?

bronsa20:09:24

you could likely use a tagged literal to achieve that

bronsa20:09:29

a bit of a hack

bronsa20:09:39

but I'd rather do that than use #=

lvh22:09:16

How do I proxy an interface method that has type m(A, B…)? ISTR the B… is syntactic sugar, but that clojure’s dot interop syntax knows how to deal with it. When I define a proxy with signature [x ys] or [x & ys], in either case I get No matching method found: m for class $myproxy.

bfabry22:09:40

@lvh the ellipsis is just syntactic sugar for a primitive java array, so you want a method where the last argument is a primitive java array

lvh22:09:29

@bfabry do you happen to know if Clojure’s dot syntax allows you to type it as one would in Java, that is, with an implicit array?

lvh22:09:32

(ISTR calling it worked fine)

bfabry22:09:59

what's ISTR? No, clojure's dot syntax requires you to pass a java primitive array as the last argument afaik

lvh22:09:09

Sorry, I seem to remember/recall

lvh22:09:59

OK, so I’m going to do something gnarly like (type (into-array Logging$WriteOption [])) and then type annotate with that?

bfabry22:09:00

boot.user=> (import '(java.util Collections ArrayList))
java.util.ArrayList
boot.user=> (Collections/addAll (ArrayList.) 1 2 3)

clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: No matching method: addAll, compiling:(/var/folders/42/zcfb2hds38l3shl7lqnjw2gh0000gp/T/boot.user7697464369495271650.clj:1:1)
     java.lang.IllegalArgumentException: No matching method: addAll
boot.user=> (Collections/addAll (ArrayList.) (into-array [1 2 3]))
true

bfabry22:09:35

I suppose that's not actually dot syntax... but I'd be surprised if the rules were different

bfabry22:09:51

boot.user=> (. Collections addAll (ArrayList.) (into-array [1 2 3]))
true
boot.user=> (. Collections addAll (ArrayList.) 1 2 3)

clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: No matching method: addAll, compiling:(/var/folders/42/zcfb2hds38l3shl7lqnjw2gh0000gp/T/boot.user7697464369495271650.clj:1:1)
     java.lang.IllegalArgumentException: No matching method: addAll
boot.user=>

lvh22:09:58

ah, there we go

lvh22:09:01

thanks 🙂

lvh22:09:05

so, to proxy that

bfabry22:09:40

I honestly can't think of a proxyable java interface/class off the top of my head. my belief is it would just work but I don't know for sure

bfabry22:09:04

java/interface with an ellipsis method sig.

lvh22:09:42

define “just work”? as in you’d expect the signature to just be (m [x ys] …)?

bfabry22:09:54

where ys is a primitive java array yes

bfabry22:09:54

why can't I think of anything that uses ellipsis...

lvh22:09:32

ugh I think I figured out the problem; the exc is just because I’m calling it with the way I thought dot syntax worked, that is — allowing varargs

lvh22:09:41

so the error is in fact 100% accurate because I’m passing 3 args and it only takes 2