This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-23
Channels
- # announcements (3)
- # asami (5)
- # babashka (1)
- # beginners (38)
- # biff (4)
- # calva (12)
- # cider (2)
- # clj-commons (6)
- # clj-kondo (46)
- # clj-on-windows (1)
- # clojure (50)
- # clojure-europe (41)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-uk (16)
- # clojured (3)
- # clojurescript (49)
- # conjure (1)
- # cursive (29)
- # datahike (6)
- # datascript (4)
- # emacs (70)
- # funcool (1)
- # google-cloud (12)
- # graalvm (10)
- # graalvm-mobile (7)
- # gratitude (4)
- # hyperfiddle (1)
- # joyride (26)
- # lsp (16)
- # malli (23)
- # nbb (5)
- # off-topic (23)
- # polylith (32)
- # re-frame (23)
- # releases (3)
- # remote-jobs (1)
- # reveal (3)
- # tools-build (16)
- # xtdb (50)
(def e "we are {{hi.there}} boo§ {{hullo.there.again}}")
(re-find #"\{\{(.*)\}\}" e)
["{{hi.there}} boo§ {{hullo.there.again}}" "hi.there}} boo§ {{hullo.there.again"]
I was hoping for something like
["hi.there" "hullo.there.again"]
How do I avoid the {}
being used for repetition (or whatever is happening?)This part .*
is greedy and doesn't exclude {
and }
characters. Try something like this:
(->> "we are {{hi.there}} boo§ {{hullo.there.again}}"
(re-seq #"(?:\{\{)([^\{\}]*)(?:\}\})")
(map second))
=> ("hi.there" "hullo.there.again")
I need to get input elementById and set its value. How can I do this in Clojurescript ?
(set! (.-value (js/document.getElementById "app-center")) "Some Text")
this will work for sure
Hi everyone, Is there a way that I could override the equality check for byte-arrays?
I have a nested structure where the top entities are being checked using equality =
I want to replace bytearray equality check to use this instead (-> byte-array seq)
So far I've only been working on my application using the REPL. At some point though, I'm going to want to deploy it to a VPS somewhere. What would be the best method to deploy production Clojure code? Is there any difference between simply clj -X
ing a function, or creating an uberjar using tools.build?
1. uberjar will have all your dependencies prepacked in one binary. for clj -X
you must ensure that it is possible to download dependencies from external repositories or provide it yourself into correct location. Sometimes it is not possible due to restrictions of VPS
2. uberjar might have faster startup time if you compile your code ahead of time
3. uberjar essentially is a container to be executed by JVM so start up command will be different from clj -X
those points are not necessarily problems, just the things worth to know about.
The short answer is: either will work fine. clj -X
might be easier to get started, and will continue to work fine. I know quite a few Clojure companies that actually do deploy and run this way. Uberjar has some benefits as @U04V4KLKC points out, but also some more things that can potentially break.
If you compile your uberjar with direct linking, that can be faster
Although technically you could do that with -X too
Hello there fellow clojurists! I’ve been learning my way around spec and test.check, to do so I’m implementing a marble race simulator, but I’m not sure the solution I’ve found to spec a set of marbles is ideal…
A marble looks like: #:bookie.marble{:color :white, :luck 3, :speed 9, :weight 5}
, which is easy enough to spec, now I’d like to spec a marble set containing exactly one marble of each color from a given set of colors. The best solution I got was doing something like:
(s/def ::marble-set
(s/with-gen (s/and (s/coll-of ::marble :into [] :count (count color-set))
#(apply distinct? (map ::color %)))
#(gen/fmap (fn [_] (map random-marble color-set)) (gen/boolean))))
I’m basically improvising a constant generator with an s/fmap
and using a function to generate a random marble for a given color. Is this the best way to do thing? Should I be using the same function that I’ll validade later to generate examples? I can’t think of any other way of generating tests efficiently…no, writing a generator this way breaks shrinking and makes it non-repeatable (the same seed when testing won't result in the same values tested)
given you have a fixed set of colors, I would generate a vector of booleans, where each position in the vector represents if a color is present or not, and then use fmap to construct the set from the vector
Huh, that sounds good, but every color should always be present…
I’m trying to make the marble set into a s/map-of
or a s/keys
with the color as a key and the properties as values…
So there is a generator for a constant value, awesome! I’ll give it a try!
generators are a turducken of monads (a monad in a monad), names like fmap and return are the result of that. return is the usual name for an operation that lifts some value into a monadic value
Hi, I have just solved problem 144 of 4clojure and I am wondering whether there is some TCO going on because even for huge numbers this recursive lazy seq doesn't fill up the stack:
(defn p144 [x f & fs]
(lazy-seq (cons x (apply p144 (f x) (concat fs [f])))))
(reduce + (take 100000000 (p144 0 inc dec inc dec inc)))
What is happening here? Thank you in advance, Zapperdulchen
reduce does not hold the head of the sequence so it can just walk down the (large) lazy sequence, looking at one element at a time while the already seen elements get gc'ed behind
I do not understand. How do I know whether something is stack recursive. Some link which explains this difference would be helpful.
@U064X3EF3 This explains why (fact 10000) behaves differently depending on the definition:
(defn fact [n]
(if (= n 1) 1 (*' n (fact (dec n)))))
(defn fact [n]
(reduce *' (range 1 (dec n))))
Didn't know that, but very helpful!
the lazy seq is not stack recursive because it doesn't call itself: lazy-seq is a macro that makes a function that is called later when the seq is realized
user=> (macroexpand '(lazy-seq (some-recursive-looking-call)))
(new clojure.lang.LazySeq (fn* [] (some-recursive-looking-call)))
Another question, I’m trying to procedurally spec a set of namespaced keywords:
(def color-set #{::black ::red ::green ::blue ::yellow ::cyan ::magenta ::white})
I’ve tried the following at the REPL:
(doall (map #(s/def % ::marble) color-set))
But the keywords don’t appear to be registered as specs when I do so :/I ended up doing this:
(eval (cons 'do (map
(fn [color] `(s/def ~color ::marble))
color-set)))
Not sure if it’s the most elegant way of doing things but it worked :)