This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-08
Channels
- # announcements (6)
- # aws (1)
- # beginners (64)
- # boot (22)
- # calva (9)
- # cider (109)
- # clara (4)
- # cljs-dev (29)
- # clojure (112)
- # clojure-europe (2)
- # clojure-italy (6)
- # clojure-nl (3)
- # clojure-russia (215)
- # clojure-spec (80)
- # clojure-uk (13)
- # clojurescript (150)
- # code-reviews (3)
- # core-async (7)
- # cursive (37)
- # data-science (11)
- # datomic (76)
- # figwheel-main (6)
- # fulcro (56)
- # jobs (3)
- # jobs-discuss (22)
- # juxt (4)
- # off-topic (11)
- # pathom (16)
- # planck (5)
- # portkey (63)
- # re-frame (22)
- # reagent (3)
- # remote-jobs (1)
- # ring-swagger (5)
- # shadow-cljs (3)
- # testing (2)
- # tools-deps (6)
Is there a way to know whether an object satisfies a protocol that's been extended via metadata? clojure.core/satisfies?
doesn't seem to work?
(defprotocol IFoo
:extend-via-metadata true
(foo [this]))
(def x (with-meta {} {`foo (fn [x] :foo)}))
(foo x)
;; :foo
(satisfies? IFoo x)
;; false
You can query whether the metadata on a given object has entries for the protocol functions you might want to call -- but it would make satisfies?
a pretty slow function if it had to walk all the metadata to look for all the protocol functions declared for a given protocol...
...and you might only provide one or two of the functions (the ones you actually know will be called) rather than all of them.
If IFoo
had two functions, foo
and bar
, and you had an object whose metadata defined just foo
, does it satisfy IFoo
or not?
@whoneedszzz for an API server that is both a server and a client, Zach Tellman's aleph looks excellent. It's built on Netty so it does all sides of networking. It's also built on Z.T.'s rip-snorting "manifold" async library. So your non-blocking code that says "in response to this api request, go ask http://bla for something and when it comes back filter it and return it to the end user" looks perfectly procedural and natural.
I'm running yada on the frontend, which uses aleph. The backend API is separate so I'm using java-http-clj on that end
That's a good point. I don't care about performance in this case so it would have been nice if there was a function in core that made a satisfies?
in the metadata. It's quite easy for me to add (contains? (meta x) `foo) in this case.
As for the second point when an object has just defined one of the functions in IFoo
, I'd expect satisfies?
to work like it does on other object who hasn't implemented the protocol fully:
(defprotocol IFoo
(foo [this])
(bar [this]))
(satisfies? IFoo (reify IFoo (foo [this] :foo))) ;; true
Thanks @seancorfield as always 🙂
I guess the check for protocols that can be extended via metadata needs to be
(if (or (satisfies? IFoo x) (contains? (meta x) `foo)) (foo x) (throw (ex-info "Don't know how to foo this!" {:x x})))
(or just let it blow up depending on what you need to do in the non-`foo`-implementing case)
Why isn't there an equivalent peek!
function for transient vectors in the standard library?
Say I have a reducing function where each step depends on the previous result and the intermediate steps are all internal
(reduce
(fn [acc val]
(let [prev (peek acc)]
(conj acc (... prev val))))
[:init]
coll)
It would be nice to easily turn it into a transient version
(persistent!
(reduce
(fn [acc val]
(let [prev (peek! acc)]
(conj! acc (... prev val))))
(transient [:init])
coll))
The only thing I could find was a 8 year old SO post https://stackoverflow.com/questions/3207298/why-is-there-no-peek-function-for-clojure-transient-vectors
Is the above code un-idiomatic in some way? I just started learning about transients but I imagine this isn't a rare use case for them.
Since a transient vector is both Counted and Indexed, I think the following should be O(1): (defn peek! [t] (nth t (dec (count t)) nil))
Not quite as fast as having it built-in but probably good enough if you're going to get enough of a performance boost from switching from persistent to transient vectors in a reduce
like that...
peek
is a read op. seems like it should just work on a transient vector, probably just an oversight
can’t say I’ve ever seen this mentioned before, but feel free to file a jira
Thanks, I filed one at https://dev.clojure.org/jira/browse/CLJ-2464 - it's my first time using JIRA so I'm not sure if it's done properly.
Yep, thanks
Where can I find information on how defprotocol's :on-interface directive works?
that’s not a public feature of defprotocol
so I don’t know of any info on it
Alright. I've just seen references in some of Rich's comments pointing towards it in the case someone had a particular use case, and I wanted to know more about it.
Most notably here: https://groups.google.com/forum/#!msg/clojure/pZFl8gj1lMs/qVfIjQ4jDDMJ
Is there something like the following for clojure.test (ideally not incurring in the banana-jungle problem; I don't want to change frameworks)
expect { ... }.to change { ... }.from(1).to(2)
that's ruby rspec in case in case it rings a bell. Else: { ... }
represents code blocks (which in clj would be fns, or macro bodies)
I actually implemented expect-change
in clj a couple jobs ago, can't access the source unfortunately
@vemv sounds like you want expectations/clojure-test
🙂
https://github.com/clojure-expectations/clojure-test -- it provides an "expect" style syntax on top of clojure.test
(so all your existing tooling continues to work).
It's not as expressive as rspec… I believe there was actually a "port" of rspec to Clojure years ago but I don't think it is maintained now.
Although I'm not sure what expect-change
would be in Clojure given the general lack of side-effect-y stuff...?
hmmm interesting! nice job on the library, I appreciate the bridging of both worlds
I was familiar with Expectations, perhaps I don't like that a lot of stuff seems to rely on positional arguments, so occasionally typos might mean false positives/negatives
> expect-change
would be in Clojure given the general lack of side-effect-y stuff...?
I'd agree with you for unit testing, but for "controller" tests (in Rails lingo) where I assert that hitting API endpoint causes side-effect x, the technique becomes more useful.
As a random thought, a macro-based impl would rock:
(expect (inc!) :to-change @foo :from 2 :to 3)
Here, (inc!)
and @foo
are evaluated in a careful, specific order
(deftest side-effect-y
(expect 2 @foo)
(inc!)
(expect 3 @foo))
:rolling_on_the_floor_laughing:are you using Component/Integrant? A nice approach would be to define per-environment components
i'd want to mock a helper function from a dependency that's irrelevant during tests without having to with-redefs every single time
I like to build it in the design of my application. Having dummy implementations for those dependencies, acting similar to the mocked dependency
actually it's in the dependency of a dependency and mocking that out feels like more trouble than just with-redefsing every test
I thought you were after an alternative testing way, but if it's about globally overriding the function.
(alter-var-root #'the-ns/the-function (constantly (fn [& args] "whatever"))
Works tooBe sure to not put it in production 🙂
what are your opinions on websocket libraries (vs. non-libraries)? I used sente for a side project and had quite some trouble getting started, many concepts to understand and quite opinionated. There’s also the possibility of just hooking into http-kit directly. Anything I’ve missed, what do you prefer?
I have a simple deps.edn, and when I run clj the java process just hangs. What would be the first step to debugging this beyond making sure the dependency exists?
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.openjfx/javafx-fxml {:mvn/version "11.0.1"}
would explain why perfectly working code didn't work on a different computer
@audiolabs you’re doing that for REBL?
@ghadi yes, I was copying a rebl config to a different system
I'm aware the deps I pasted aren't the full reqs
it's just the minimum that cause the java process to hang
we have a fix for that now: https://github.com/cognitect-labs/REBL-distro/issues/10#issuecomment-451173909
yeah, definitely make sure you’re using latest clj (now 1.10.0.411)
Getting a maven error for that version string.
that’s not a Maven artifact
that’s the clj version (for the Mac brew installer or in the linux scripts at https://clojure.org/guides/getting_started)
So the 1.10.0 artifact pulls the latest?
they are separate things
you need clojure (Maven artifact org.clojure/clojure, version 1.10.0)
and the clj tool (version 1.10.0.411), which you can install with the instructions on the link above
I misread what you were saying. I'm unfamiliar with the clj tool
What are you trying to do?
This thread started with a question about how to use the clj
tool for REBL with Java 11 and Clojure 1.10
I just wanted to make sure I was on the latest version. I misread what you were talking about is all.
ok. 1.10.0 is the newest version of Clojure :)
I am on Arch Linux and just install the clojure
package. Now I'm just mainly curious if it is the latest version since it just prints out the Clojure version and not the version of the tool itself.
Looks like it is on 1.10.0.408
I’m not sure what the Arch package is or who makes it, but that sounds like the clj tool. You should be able to type clj
at the terminal to get a repl.
the version of clj
is actually independent from the version of Clojure you use
any version of clj can use any version of the Clojure language
I understand they are two different things so we're good on that
yeah, that’s just a variant of the linux installers listed at https://clojure.org/guides/getting_started
Right and - usr/share/clojure/libexec/clojure-tools-1.10.0.408.jar
So it's slightly behind
yeah, just one fairly esoteric bugfix in 411 vs 408 so you are highly unlikely to care
Exactly
is there an alternative to doing (merge-with (fn [x y] (or x y)) {:a nil} {:a "val"})
without having to create an anonymous function?
isn’t that just (merge-with or ...)
oh, macro
I can’t think of an alternative that’s clearer (other than to avoid having nils in the first place)
https://github.com/igrishaev/etaoin works quite nicely for me.
hey guys, tearing my hair out over this error i’m getting … some dependency load is failing with ExceptionInInitializerError
. this only happens when i run the program on our aws deployment. everything works fine locally. anyone seen this sort of thing before?
i’m sure the lack of deployment details probably isn’t very helpful, but any place to even start looking would be appreciated
the print statements i put in all of the dependencies all appear in the logs, so it looks like they’re all getting compiled, oddly enough
Not sure where to report this, but seems that Clojure 1.9 is missing from https://clojure.org/community/downloads_older ? Spotted because https://clojure.org/community/downloads currently lists Clojure 1.10, but other page only goes up to 1.8. If someone points me in the right direction I can raise a PR (.patch?) on this later, but if it's easy to fix now then go ahead
If you haven’t completed the 2019 Clojure survey, now’s a great time - takes about 5 minutes. https://www.surveymonkey.com/r/clojure2019

I wasn’t sure what to expect with Java usage in the survey but the early results are … interesting
Haha... "Common household products that can kill you instantly. More at 11" 😂 Captured our interest for sure.
Still stuck in Java 7 Land at work... and https://github.com/yetibot/yetibot/issues/804
oh, just wasn’t sure how people are rolling with the whole Java 9/10/11 and LTS release schedule
I’ll refrain from details till we get through the whole survey period