This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-03
Channels
- # aleph (6)
- # announcements (4)
- # babashka (73)
- # beginners (117)
- # calva (25)
- # chlorine-clover (59)
- # cider (21)
- # clara (3)
- # cljdoc (8)
- # cljs-dev (54)
- # cljsrn (15)
- # clojure (65)
- # clojure-france (5)
- # clojure-spec (3)
- # clojure-uk (13)
- # clojurescript (79)
- # conf-proposals (1)
- # conjure (17)
- # core-logic (11)
- # datomic (21)
- # fulcro (82)
- # graalvm (11)
- # helix (7)
- # jobs-discuss (11)
- # joker (2)
- # juxt (3)
- # local-first-clojure (1)
- # luminus (5)
- # nrepl (61)
- # off-topic (12)
- # pathom (70)
- # re-frame (3)
- # reitit (3)
- # rum (1)
- # shadow-cljs (58)
- # sql (1)
- # tools-deps (26)
- # xtdb (3)
I believe there's a ticket about it
Hi! If I have a namespace that only has a defmethod
in it, how do I force it to load? Just importing it in the namespace that is called on entry-point doesn't seem to do a trick.
@bear-z You just require
it like any other namespace.
That's what I'm trying to do, but it doesn't seem that it loads.
I even put a println in it and it doesn't fire.
I do (:require [myapp.mynamespace])
inside my .app namespace that is called on entrypoint. I do it in ClojureScript, but I don't think it matters in this case.
I never use it, since I just want to add an implementation of multimethod
No idea about cljs so maybe ask in #clojurescript ?
I'll try, thanks!
I don't understand this at all... I haven't been able to make a small reproducible example yet, but I have a function that uses an atom internally. When I return the atom from the function, it shows with the correct contents, when I deref the atom before returning it, it shows empty (with the initial value)
Alright... Took me about a hour, somewhere in a function I was using a map, in other words lazy-sequences. Printing the atom resolved the lazy-sequences and made the changes to the atom. Moral of the story: don't use atoms if you can help it
while "don't use atoms if you can help it" is certainly helpful, this seems to rather be about a case for "make sure you're using/not using lazy-sequences where you expect you're using them"
Anyone know if there is anything similar to https://github.com/CITGuru/PyInquirer for Clojure?
@U093DA4QY, there’s https://github.com/mabe02/lanterna, but you have to suffer a Java API
I recently used lanterna to add a terminal graphics backend to https://github.com/phronmophobic/membrane, but I haven’t released it. If you’re interested in something a little experimental, I can make a new release.
here’s TODO mvc running in the terminal (with mouse support!)
interesting, thanks @U7RJTCH6J!
fyi, there was a similar thread in #off-topic with a good suggestion if you’re using cljs, https://clojurians.slack.com/archives/C03RZGPG3/p1588543676426200?thread_ts=1588541027.424900&cid=C03RZGPG3
Yeah there is https://github.com/CITGuru/PyInquirer if you are okay using libpython-clj
Any comments on this code?
(defn split-when
"Like partition-by but splits collection only when `pred` returns
truthy value. E.g. `(split-when odd? [1 2 3 4 5]) => ((1 2) (3 4) (5))`"
[pred coll]
(when-first [x coll]
(if (not (pred x))
(cons (list x) (split-when pred (rest coll)))
(let [tail (split-when pred (rest coll))
coll (first tail)]
(cons (conj coll x) (rest tail))))))
Maybe a lazy-seq
would be better?
(defn split-when
"Like partition-by but splits collection only when `pred` returns
truthy value. E.g. `(split-when odd? [1 2 3 4 5]) => ((1 2) (3 4) (5))`"
[pred coll]
(when-first [x coll]
(if (not (pred x))
(cons (list x) (lazy-seq (split-when pred (rest coll))))
(let [tail (lazy-seq (split-when pred (rest coll)))
coll (first tail)]
(cons (conj coll x) (rest tail))))))
suggestion:
name: split-at
api: [pred coll]
will return a lazy seq, [pred]
will return a transducer?
@UK0810AQ2 split-at
already exists in core
I don't need a transducer myself, but that would be good to add if this went into a public library
Oh I see. Then the result should have been something like ((1) (2 3) (4 5))
or am I misinterpreting?
no, the predicate is odd, so it should only start a new collection when it returns true
so it starts with 1, because that's odd, until it encounters a new odd number, then you'll get a new coll
(split-when odd? [0 10 12 3 4 5])
returns ((0) (10) (12) (3 4) (5))
so I assume there is a bug somewhere there?
I think it is because it's a bit ambiguous on the starting element. It seems to me that you want to start with a list with the first element in no matter what the predicate, and then split when pred is thruthy else accumulate on the list.
You actually want partition-by
but with a twist. When partition-by
splits it includes the split element at the new list while you want to retain it in the current list. But with this approach you will end up with an empty list in the sequence in certain occasions if you want to refrain from crazy things like including the first element regardless of the predicate.
how about something like this:
(defn split-when
[pred coll]
(lazy-seq
(when-let [s (seq coll)]
(let [fst (first s)
f (complement pred)
run (cons fst (take-while #(f %) (next s)))]
(cons run (split-when pred (seq (drop (count run) s))))))))
basically a copy of partition-by
with the logic tweaked in the run part
@U1XTUTPMY That looks like it!
my original use case was more like this:
(split-when symbol? ['foo 1 2 3 'bar 5 6]) ;;=> ((foo 1 2 3) (bar 5 6))
@U1XTUTPMY nice! One small detail is that you are wrapping the drop
call with seq
instead of lazy-seq
I'm not sure why/if the seq needs to be there. I just copied the code from partition-by
so... presumably it is correct enough
partition-by
has the lazy-seq there and I think it is there to defer the drop call on the "next" consumption
ah, I suppose you're right. The projet I was messing around in is still using 1.8 so (source partition-by) didn't have the lazy seq there. @U04V15CAJ ^
@U1XTUTPMY oh, so seq
should be lazy-seq
just before drop on the last line?
[.. looks like it's the same answer as above lol .. I just used the first one.] I wound up solving a similar problem (in gap scheduling) with the partition-between from the answer here (for a contrast). https://stackoverflow.com/questions/23207490/partition-a-seq-by-a-windowing-predicate-in-clojure?rq=1
Clojure: operations are efficient by default, so conj
adds to beginning or end of the collection depending on it's type to make it always O(1)
Also Clojure: when interop is reflecting, it's at most a warning
If you’re having trouble with interop, I’d recommend Cursive. It takes a lot of pain out of it.
good point, but still not true for interop (.foo bar)
has wildly different performance implications depending on bar
's type hinting
Yeah, it’s a pain. I’m so used to it (and used to Cursive’s help), that I don’t feel it much anymore.
I use cursive and don't have any troubles with interop, it's just a joke I came up with after seeing this reddit post: https://www.reddit.com/r/Clojure/comments/gcry9d/why_does_my_clojure_implementation_of_conways/