This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-12
Channels
- # arachne (1)
- # aws (2)
- # beginners (123)
- # boot (22)
- # boot-dev (8)
- # chestnut (3)
- # cider (38)
- # clara (36)
- # cljs-dev (148)
- # clojars (2)
- # clojure (76)
- # clojure-austin (2)
- # clojure-greece (1)
- # clojure-italy (6)
- # clojure-russia (5)
- # clojure-spec (8)
- # clojure-uk (65)
- # clojurescript (45)
- # core-async (38)
- # cursive (9)
- # data-science (5)
- # datomic (28)
- # docs (1)
- # emacs (2)
- # fulcro (34)
- # hoplon (18)
- # jobs-discuss (7)
- # keechma (8)
- # lumo (5)
- # om (3)
- # onyx (31)
- # parinfer (1)
- # pedestal (1)
- # re-frame (20)
- # reagent (5)
- # ring-swagger (16)
- # shadow-cljs (56)
- # spacemacs (11)
- # specter (8)
- # sql (5)
- # unrepl (29)
- # yada (6)
does clojure have a tool that does something like this: input: here's a bunch of code here's a bunch of tests output: give me a list of sexps in the code that were NOT executed when all the tests have been run
anyone familiar with how this black magic: https://github.com/klutometis/reader-macros works ?
hacks the Clojure reader to open up the dispatch tables and simulate lisp reader macros
How do I set a breakpoint in cloverage
to debug how it fails to instrument a piece of code?
(def _1 20)
<-- is this asking for trouble? I'm doing some pattern matching work, so I'm thinking of naming some pattern vars _1 2 3 ...
I am not aware of any parts of Clojure that would break because of using names for Vars like that.
You might confuse some readers of the code.
You are on the right side of the official docs for symbol names with such names: https://clojure.org/reference/reader#_symbols
The symbol by itself is by convention_ only used for Vars or locally bound names (e.g. in let/loop binding forms) that will not be used in the body.
I mean to start that last sentence with "The symbol '_' by itself", but my Slack special formatting-fu is weak.
Great; thanks, I think I will be okay, as I tend to use 1 2 only "pre macro expansion", in that I have these rewrite rules defined as: (add 1 2) -> (+ (eval context 1) (eval context 2)) then this "rule" gets translated into a sexp with destructuring , let, <-- and symbols in this form are all gensymmed, so there's no actual 1 2 n the 'post macro' final code
I have an array of maps. I want to update one of the maps by matching on one of its properties. This (for [x arr] (if (== (:id x) 21) (assoc x :name "new") x))
works, but is there a more idiomatic way. Something like a assoc
where the match is an arbitrary predicate?
@lee.justin.m Specter is your friend for these things:
user=> (def a [{:name "foo" :id 1} {:name "bar" :id 2}])
#'user/a
user=> (transform [ALL (selected? :id (pred= 2))] #(assoc % :name "not-foo") a)
[{:id 1 :name "foo"} {:id 2 :name "not-foo"}]
I'm trying to learn clojure spec
from the offical site,
but I don't understand the instrument
and check
.
Does it replace testing? Should I count on random generation for production testing?
When should I use it and what functions should I spec?
Do you look at "Property based testing" ? https://vimeo.com/217133774 https://www.youtube.com/watch?v=shngiiBfD80 http://blog.charleso.org/property-testing-preso/#1
How can I create a var from a string, e.g. like (var (symbol "bidi.bidi/match-route"))
(this doesn’t work)
(resolve (symbol "clojure.core" "get"))
or (resolve (read-string "clojure.core/get"))
I'm trying to spec a configuration function.
The function input is env vars (map of keyword to string),
and return the port
as an int.
How should I write the s/def
for the key port
, once for string
and once for int
?
(def port-regex #"\d+")
(s/def ::port (s/and string? (partial re-matches port-regex)))
(s/def ?port? int?)
(s/def ::config (s/keys :req-un [::port]))
(s/def ::parsed-config (s/keys :req-un [?port?]))
The above suggestion sounds good, but ::port-output
can be just ::port
as it's the expected format
yea but I want the return map to contain :port
key, and the input map already contains :port
key
I don't have the full picture but what I'd go with is
(s/def ::port (s/or :parsed-port ::parsed-port :port-str ::port-str))
- ::parsed-port and ::port-str are both ports, they just differ in representation.
- Your function receives a ::port-str and returns a ::parsed-port
anyone using autoformatters or similar tools has recently had as->
receiving a different indentation style?
we haven't updated cljfmt
or such. dunno where the change comes from
After setting a function spec
, where should I validate it?
Should I use conform
in the beginning and throw in case of an :invalid
?
@itaied you can use the clojure.spec.test.alpha namespace https://clojure.org/guides/spec#_testing
Anyone know what the :v :d :a scores mean in the following library? https://github.com/damionjunk/sentimental
;; Compute the EN ANEW for the provided phrase
(anew/score-phrase "I really love my dog." :english)
;; => {:words ["love" "dog"],
;; :score {:v 8.145000219345093, :d 6.680000066757202, :a 6.1000001430511475}}
@josh_tackett from the paper cited in the readme: valence, arousal and dominance
@schmee @lee.justin.m a cleaner way to do it with specter: (setval [ALL #(= (:id %) 2) :name] "not-foo" a)
Any ideas how to debug why clojure.tools.namespace/refresh
fails with “namespace … not found, compiling:(dev.clj:1:1)“? I’ve got no AOT compilation settings or anything that should intervene with the reload but still it does not work
The class is loaded properly the first time I enter the REPL
in the dev.clj file
@schmee Do you know a good clojure sentiment library?
looks like https://github.com/damionjunk/sentimental is in SNAPSHOT
@josh_tackett no idea, sorry
Ah, it seems that the namespace fails to reload because of something in its contents. I replaced it with just an empty ns declaration and now it refreshed properly
@fmind isn't that for testing? I meant to ask about runtime validations, reject and accept requests according to the spec
I use this approach:
- create a little helper that throws/reports errors if something is not valid?
. Good place to wrap expound
(a library) as well
- integrate the helper into :pre / :post / assert
you can use orchestra to test everything https://github.com/jeaye/orchestra
but it's a trade-off, spec was written so that only the inputs are checked. This is usually the most common source of 'trivial errors'
and you can also use the :pre :post assertion built-in defn http://blog.fogus.me/2009/12/21/clojures-pre-and-post/
the trick is to wrap things in assert
, which can be optionally elided in clojure(script)
1. I realize that most functions should be pure.
2. Occasionally, we write functions f
, where the idea is that (f 3 g)
means that w emake galls (g 0) (g 1) (g 2), in that order, for its side effects.
3. What is a good way to unit f
via clojure.test ?
We do that by passing in a 'test' implementation of g
that does a (swap! expected-g-calls conj params-to-g)
, where expected-g-calls
is (atom [])
Then once f
has returned we check that expected-g-calls
contains the stuff we thought it should, in the order we thought it should
We tend to do the functional core/imperative shell split, and anything that's going to require with-redefs
to test and can't be refactored for that not to be the case goes in the shell
in particular, let's say we want to unit test a function:
(defn f [n g]
(doseq [i (range n)] (g i)))
@carr0t: yeah, most of the time, we try to split pure/imperative too; in this particular case, we're building a "distributed object", so we're trying to test things like: when an update is called on this obj, these registered handlers fire off ...
boot.user=> (require '[clojure.test :refer :all])
nil
boot.user=> (defn f [n g]
#_=> (doseq [i (range n)] (g i)))
#'boot.user/f
boot.user=> (let [g-calls (atom [])
#_=> g (fn [i] (swap! g-calls conj i))]
#_=> (f 3 g)
#_=> (is (= [0 1 2] @g-calls)))
true
1. this is slightly less elegant/verbose compared to previous uses of (ct/is (= ...lhs... ...rhs...)) 2. I don't think one can make it more elegant/concise
@schmee @nathanmarz Thanks for the tips. specter is the boss and is just what I need.
I find exception handling inside of let bindings a bit awkward, and I ran into this try-let
project looking for answers. It doesn't really seem like people use it much, so I'm wondering if anyone here has thoughts on alternative ways to address these issues in the motivation
section: https://github.com/rufoa/try-let#motivation?
@bj i usually catch within the bindings and bind a value to the symbol that captures the failure and check for it in the body
If you were going to add automated acceptance tests to a full stack Clojure(Script) project today, what would you use?
I’ve used clj-webdriver
before with mixed results. Is there anything else I should look at?
We've used clj-webdriver
for several years but it's essentially abandonware at this point so I've been wondering about writing new tests in etaion
-- can folks give any experience reports about it?
@U04V70XH6 quite limited but I'm happy with it . So far, my main concern was the setup - for chrome quick & easy, the tests are easy to write and work beautifully. However, the tests failed on safari/firefox (I didn't dig into the details yet).
We are using it at room key and really enjoyed the ease of which you can use it from the repl. It makes the process of writing tests very quick and interactive. We haven't had any serious problems so far, I submitted a small bug fix or two and Ivan has been quick to respond to our feedback
@U06060CK0 That's great feedback, thanks. Knowing it suits REPL-driven test development is very useful, and that the maintainer is responsive. @U06BE1L6T Interesting. We've found clj-webdriver
to be really flaky with Chrome but rock solid with Firefox so that would be a bit of a shift for us.
i’ve also used https://github.com/Mayvenn/limo
Does anyone know of any whitespace-aware Clojure parsers or approaches to build such?
I haven't used it, and I think even the author may anti-recommend it, but sjacket is in that category of tools: https://github.com/cgrand/sjacket I do not know the reasons it may be anti-recommended, if it is.
sjacket is used for its clojure parser which is based on parsley (which I’m not super happy with). One day I will be fed up and I’ll write a drop in replacement based on instaparse.
We've used clj-webdriver
for several years but it's essentially abandonware at this point so I've been wondering about writing new tests in etaion
-- can folks give any experience reports about it?