This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-18
Channels
- # atom-editor (5)
- # babashka (15)
- # beginners (80)
- # calva (11)
- # cestmeetup (6)
- # chlorine-clover (15)
- # cider (22)
- # circleci (3)
- # clojure (57)
- # clojure-europe (19)
- # clojure-italy (1)
- # clojure-nl (4)
- # clojure-spec (1)
- # clojure-switzerland (1)
- # clojure-uk (88)
- # clojurescript (92)
- # code-reviews (1)
- # cursive (6)
- # data-science (5)
- # datascript (6)
- # datomic (12)
- # events (7)
- # figwheel-main (2)
- # fulcro (55)
- # graalvm (2)
- # helix (6)
- # juxt (6)
- # kaocha (11)
- # luminus (2)
- # off-topic (82)
- # pathom (27)
- # portal (1)
- # re-frame (3)
- # reitit (25)
- # remote-jobs (8)
- # sci (11)
- # shadow-cljs (29)
- # slack-help (2)
- # spacemacs (9)
- # specter (4)
- # sql (9)
- # tree-sitter (1)
- # uncomplicate (1)
- # xtdb (26)
just to confirm, smt in clojure (alter) only offers snapshot isolation, and still suffers write skew ?
do you mean stm?
the correct way to use stm is to write code that uses the snapshot value meaningfully (except the null case of unconditional rewrite...), and the retry mechanism plus ref capture will help that function keep things coherent
that won't save you from the sort of error your function could make in a single thread, but makes preventing concurrency errors much easier
@i to directly answer your question, the retry mechanism of transactions means write-skew doesnt' happen if you use it correctly
You can use βensureβ on reads to prevent write skew if needed
oh yeah, I should have name checked that instead of vaguely mentioning "ref capture", thanks
yup. ensure. I forgot that. so that indicates alter re-tries only if the ref it refers to have been updated, not the world state (all refs in a transaction).
Only if the refs tracked in a transaction, which is all writes and reads you mark to include with ensure
iirc the classic ants demo from Rich Hickey demonstrates that write-skew doesn't happen can be effectively prevented
write-skew can definitely happen
ensure prevents it but reduces concurrency, but have control to choose
is rand-nth not working on sets intentional or accidental? if intentional what's the reasoning?
I guess "nth" is in the name, but since it's point is to not care about the order, erroring on sets seems like a misfeature
how can we use ns meta to run tests using kaocha
for example if I have (ns ^:foo file1-test)
(ns ^:foo file2-test)
how can I run just both of them using the ns meta
There is a :focus-meta
config we can specify in tests.edn
but the problem Iβm facing is it runs only the first match.
Has anyone got an idea what on Earth is going on here?
(require '[co.ytems.model.money-amount])
=> nil
(require '[co.ytems.model.money-amount :as money])
Syntax error compiling at (/private/var/folders/62/3v4gckg15t706bjzkjw155n00000gq/T/form-init6286340574717549821.clj:1:1).
namespace 'co.ytems.model.money-amount' not found
any chance you edited the file and it no longer declares the same ns
symbol in the declaration as the one you required?
No that wasn't it.
I'm still quite at a loss as to what happened, because even though lein clean
appears to have solved it, there's still quite a lot of garbage in target/
I've avoided learning too much about these issues by not using aot or gen-class
it's a corner of the language / tooling that I find wastes my time and energy, ymmv, it's not hard to ensure you never need aot or gen class then you rule out these sorts of errors
I agree! Not necessarily up to me unfortunately π
Thanks for the advice
there's also the technique of using a java shim - if your consumer is a java framework or app that needs a specific class / interface to load, you can make a very small java file that uses the Clojure api to load up your implementation
eg. this is enough to use clojure via the jsvc
service without gen-class or aot: https://github.com/noisesmith/clj-jsvc-adapter/blob/master/src/java/org/noisesmith/Cljsvc.java
it uses convention over configuration (provide an ns name via system property, implement a series of "magic" functions) to be as minimal and streamlined as possible but still reusable
Is there an idiom for coercing a val to a collection if a collection was not passed?I'm using this at the moment:
this should really be a FAQ, but the tl;dr version is that it intentionally doesn't exist because it's an antipattern to accept both colls and individual items in the same code path
the best solution is to never accept colls and individual items in the same code path
if some API you have to use forces you to do so, do this in exactly one dedicated API adaptor function, not a reusable converter - stop the duality in its tracks before it hits your actual codebase, it causes rippling complexity and mess
every seq?
is also a coll?
and many data types can be (and usually should be) treated as collections - there's seqable?
to check for them, and seq
if you need to explicitly convert (but most collection functions already call seq for you)
I was just perusing that article. Now I have to pay attention. thanks @U0FTV149X
(cond (coll? x) x (seq? x) x :default [x]))
Thanks. I got tripped up since (coll? (seq [])) is false. But that is since (seq []) is nil not a seq. I was hoping for something simpler like (into [] x) but into doesn't support that usage.
Yep. I switched to that from the (cond. Now thinking about a more general into: (into* coll & args) that handles both collections and values.
as mentioned in the thread above, there's also seqable?
- depending on how you would treat eg. strings, hash-maps, arrays
org.noisesmith.hammurabi.hold-my-beer=> (pprint (map (juxt identity seqable?) [nil [] "" () #
{} {} (byte-array 10) 1 (reify Object) (fn [])]))
([nil true]
[[] true]
["" true]
[() true]
[#{} true]
[{} true]
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] true]
[1 false]
[#object[org.noisesmith.hammurabi.hold_my_beer$eval15945$reify__15946 0x130a3d99 "org.noises
mith.hammurabi.hold_my_beer$eval15945$reify__15946@130a3d99"]
false]
[#object[org.noisesmith.hammurabi.hold_my_beer$eval15945$fn__15948 0x22895cca "org.noisesmit
h.hammurabi.hold_my_beer$eval15945$fn__15948@22895cca"]
false])
nil
Okay so I have this method that applies highlights to hiccup and cannot figure out how to get the highlighted vector to not be in a seq
(defn find-body-text
[hiccup rule]
(into []
(for [element hiccup]
(cond
(string? element) (highlight-text element (:regex rule) (:color rule))
(vector? element) (find-body-text element rule)
(some? element) element))))
Call=>
(find-body-text (labelmaker.views/playground) {:regex #"quick" :color "#333"})
Returns =>
[:div
[:span.p-3]
[:p ("The " [:mark {:style {:background-color "#333"}} "quick"] " brown fox jumps over the lazy dog")]]
I feel like I am missing something on getting the highlighted text from ("The" ...) to just items in the outer vector.
that should blow up and tell you that "The" isn't a function
Sorry edited to show the defn, call, and return
I want the highlight-text to return just "The " [:mark {:style {:background-color "#333"}} "quick"] " brown fox jumps over the lazy dog"
instead of ("The " [:mark {:style {:background-color "#333"}} "quick"] " brown fox jumps over the lazy dog")
what does highlight-text
do?
you can't return multiple items without some collection around them
Applies a regex to some text string and returns a vector of strings and hiccup :mark items
if you don't want it to be a list, you can use vec
to make it a vector instead, which hiccup should do the right thing with here
that's clearly not a vector of strings
perhaps you are using the result of a regex split that is in a list or lazy-seq? anyway, vec in the caller or in the function itself would both suffice surely
The other two cond options only return 1 item which I think is my issue, is there some way to pull each item out into the parent vector?
@isak my last case was just returning the keywords, but seems like I need to treat them different and start each new vector after seeing one.