This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-11
Channels
- # aleph (4)
- # beginners (68)
- # boot (21)
- # chestnut (1)
- # cljs-dev (72)
- # clojure (64)
- # clojure-austin (9)
- # clojure-dusseldorf (16)
- # clojure-gamedev (2)
- # clojure-italy (32)
- # clojure-russia (80)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (105)
- # cursive (5)
- # data-science (5)
- # datomic (23)
- # defnpodcast (3)
- # emacs (22)
- # fulcro (2)
- # graphql (63)
- # hoplon (7)
- # lein-figwheel (17)
- # lumo (63)
- # mount (2)
- # nrepl (4)
- # off-topic (66)
- # om (6)
- # onyx (3)
- # portkey (54)
- # re-frame (12)
- # reagent (12)
- # specter (42)
- # uncomplicate (1)
- # unrepl (38)
- # vim (9)
- # yada (3)
If you mean throw, it's (throw (ex-info "An exception" {:some :data}))
or substitute (ex-info ...)
for any other exception.
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.
Ok. You could just implement clojure.lang.IDeref
which is what future
and promise
etc implement.
I need to reify IDeref and IFn (and it works) There is some way to do not need to reimplement IFn?
(let [v (reify
IDeref
(deref [_] (throw (ex-info "bang!" {}))))]
@v)
user=> ExceptionInfo bang! clojure.core/ex-info (core.clj:4744)
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.
QUESTION: Is there a partition-by which has f taking the previous or all already created partitions as well as the next element?
For context, I'm trying to partition every time next element is smaller then previous element
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 ?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
@didibus what do you expect for (8 4 7 6 10)
?
(that code returns ((8) (4 7 6 10))
)
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.
Thanks, also @noisesmith
@noisesmith sorry for the ninja 😁
haha no need to apologize, I ninja all the time
with a bit of effort you could have phrased that as an apology
actually I bet the best result would come from transduc
which would match transduce
transducing
transducer
etc.
@vinai there is a list at https://clojure.org/reference/transducers
@alexmiller Oh, thanks, I missed that. I was scanning the page for a list, not a paragraph.
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?
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?
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
.
@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
@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?
what's ISTR? No, clojure's dot syntax requires you to pass a java primitive array as the last argument afaik
OK, so I’m going to do something gnarly like (type (into-array Logging$WriteOption []))
and then type annotate with that?
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
I suppose that's not actually dot syntax... but I'd be surprised if the rules were different
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=>
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
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
Bump :(