This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # architecture (2)
- # beginners (83)
- # boot (472)
- # cider (10)
- # cljsrn (4)
- # clojure (80)
- # clojure-russia (7)
- # clojure-spec (34)
- # clojure-taiwan (1)
- # clojure-uk (7)
- # clojurescript (19)
- # core-async (5)
- # emacs (7)
- # figwheel (1)
- # hoplon (52)
- # jobs (1)
- # luminus (14)
- # om (1)
- # om-next (3)
- # perun (69)
- # proton (2)
- # protorepl (4)
- # re-frame (28)
- # reagent (6)
- # remote-jobs (1)
why are regexes not checked for equality of their contents, like strings are?
(= #"a" #"a") => false
I am just imagining because no one bothered until now, but I am curious of usecases for comparing the equality for regex objects.
I know you are the pro in terms of this, but comparing the result of .pattern on the regex won't do in your case?
I was hoping I could do some kind of recursive equality function (like
=) that would magically handle regexes, but I may have to roll my own function that tests the
str of each regex when it tries to compare regexes...
When I do this :
defn ->long [s] (try (Long/parseLong s) (catch Exception _ ::s/invalid))) (s/def ::page (s/and (s/conformer ->long) (s/int-in 1 471))) (s/def ::optional-page (s/nilable ::page)) (defn page-check [page] (let [page page page-num (or (s/conform ::optional-page page) 1)] page-num)) (s/fdef page-check :args (string? (::page :page)) :ret (number? (::page :page)) :fn (s/valid? true? (::page :page) ) )
and then this in repl :
(require '[clojure.spec :as s]) => nil (require '[clojure.spec.gen :as gen]) => nil
and then :
(gen/generate (s/gen ::page)) Exception Unable to resolve spec: :user/page clojure.spec/reg-resolve! (spec.
Hi! just made a lib, would love to have feedback on it, it has README full of examples. it is related to types and polymorphism https://github.com/pbaille/facets
@roelof, the exception is due to that
::page resolves to a keyword with the current namespace as prefix. In your file it resolves to
:your-ns/page and in the REPL it resolves to
:user/page. If you instead type
(gen/generate (s/gen :your-ns/page)) (and replace your-ns with your actual namespace) in the REPL the spec should be found. You need to require that other namespace in the REPL as well.
@henriklundahl Probably, it will be easier to find answer about clojure-spec in #clojure-spec channel
Hey, guys. Can someone suggest image processing library for clojure? It's necessary for me to have ability just to resize images. Less dependencies - better, faster - better. I found two options: https://github.com/mikera/imagez https://github.com/josephwilk/image-resizer Which one is better? Any suggestions?
@henriklundahl thanks, I now have this output :
(require '[clojure.spec :as s]) => nil (require '[clojure.spec.gen :as gen]) => nil `(gen/generate (s/gen :paintings2/page)) => (clojure.spec.gen/generate (clojure.spec/gen :paintings2/page)) (gen/generate (s/gen :paintings2/page)) Exception Unable to resolve spec: :paintings2/page clojure.spec/reg-resolve! (spec.clj:68) (gen/generate (s/gen :paintings2.routes.home/page)) RuntimeException Var clojure.test.check.generators/large-integer is not on the classpath clojure.spec.gen/dynaload (gen.clj:21)
@roelof either way, you should be asking the spec questions on #clojure-spec imo, plenty of activity there, sometimes more than this channel
clojure solutions -> https://github.com/tdantas/js-clj-challenge/tree/master/clj and js solution - > https://github.com/tdantas/js-clj-challenge/tree/master/js clojure the first solution was trying to use a ‘trie’, but I’m getting very poor time with my solution and the second one I’m using a map with all word prefixes. js solution was using a ‘trie’ like
it can be reduced to O(n) map lookups, by manually walking the map instead of using reductions on prefixes of the strintg
I need a macro which outputs (catch Throwable ...) when expanded in a .clj file and (catcj js/Error ...) when expanded in a .cljs file. How can I do this? I'm looking for the equiv of #+clj and #+cljs, but in macros instead of *.clj files
(:ns &env) — it will be
nil in Clojure and non-`nil` in ClojureScript.
hey @qqq, thx, > it can be reduced to O(n) map lookups, by manually walking the map instead of using reductions on prefixes of the strintg how it would be ?
@oliv: suppose the string i abcdefghijklmnopqrstuvwxyz: the existing code firs tdoes 26 lookups (on the full string), then 25 lookups, then 24 lookups, ... then 3 lookups (ln abc), then 2, then 1
yep, that would be awesome, much better big O. but I really don’t know how to improve that
here's a starting point; probably buggy edge cases // never tried this code myself: (loop [current-map ... remaining-string ...] (increment current count) (if (not= remainig-string "") (let [first-chart (first remaining-string) rst (rest remaining-string)] (recur (descend current-map first-char) rst))))
the use of reductions is very clever; I think the main problem is that this problem was desitgned to test O(...) rujnning time, and the reductions solution provides a O(n^2) instead of a O(n) solution
the code makes O(n) updates, but the updates would take 26 lookups, then 25 lookups, then 24 lookuyps, then 23 lookups, etc ...
> so this ends up gbbeing O(n^2) map lookups
let’s suppose a word with 3 characters
“ABC”, the reductions will generate a sequence of “A” “AB” “ABC”
where are we going to use quadratic O(n^2) lookups ?
(update out current #(if %1 (inc %1) 1)))
oh, thank you. would love to know that why “AB” is 2 lookups and “ABC” 3 lookups on map data structure?
oh, I’m reading that code @qqq
(defn add [map word] (reduce (fn [out current] (update out current #(if %1 (inc %1) 1))) map (rest (reductions str "" word))))
the first one (solution_one.clj) , I agree it has a worst performance than that one ^^
@qqq Glad that worked. I ran across it in a couple of
.cljc code bases but haven’t really explored the implications of mixed language macros yet.
in cljc files, what is the right way to :require macros so that it works nicely from both clj and cljs land?
how do i annotate a method argument for a function in a namespace with gen-class which overrides a method with annotated parameters?
the method and class i am tyring to override is a library class and the annotation in question does some processing on the argument which i dont want to implement myself and just use the annotation if possible
what is the relation between fn and fn*, and where can I find the documentation for fn* ?
seancorfield: fn* shows up when I do (macroexpand '(...)); and unfortunately there's a bug somewhere in my macro 😞
separate question: I have already done (spec/check-asserts true); however my (s/fdef ...)s seem to be ignored (i..e function returhining things that clearly violate return condition); how do I figure out what I'm doing wrontg
:fn are only checked via generative testing (`clojure.spec.test/check`), not
instrument. The latter only checks
seancorfield: in other words, 1) check-asserts acts like instrument and 2) instrument only checks :args ? okay, got it; thanks
Yup. See various
clojure.spec talks online for why that is — TL;DR:
:args is about checking that functions are called correctly during example-based testing or regular code execution, whereas
:fn is about specifying the behavior of a function and verifying its correctness, which needs generative testing. Lots of discussion about this on the mailing list too since it has been a bit … contentious … at times 🙂
fn* — that’s the magic internal name that implements the behavior of the
fn special form. So it’s basically how
fn is implemented in the underlying Java code of the compiler.
@seancorfield : one thing I do not understand. I imagine "s/fdef" as a "wrapper" around the function which checks the :args before calling the function and checks the :ret after the function returns (but before the wrapper returns); briefly, can you explain what technical decision led to splitting of :args vs :ret for check-asserts? it seems like the overhead for the two is identical (modulo the actual cost of running the :ret checker)
As I said, it’s a TL;DR kinda thing — you really need to watch some of the talks and read the discussion on the mailing list.
The basic premise is that
:args checks calling code is correct but
:fn check that the function itself is correct and you need more than just example-based testing for that to be useful.
Generative testing will create valid input and verify that the output is valid (and that the relationship between the output and the input holds).
Given Rich’s preference for not complecting concerns, I would have expected
s/fdef to really be two separate pieces — but in early alphas,
instrument did check
:ret and it was very surprising to people who found that
test.check was required because it was using generative testing (and several of us expected just a plain ol’ check of the returned values, not generative testing of the contract of the function itself).
(so it was clear from that behavior that Rich’s intention was definitely that we had two different types of testing at play here!)
@seancorfield: I still don't understand this issue, but I am convinced that I should just go listen to a bunch of talks. (I listened to a few already, but they were more of the 'how to use spec', not 'design and implementation of spec' flavor). Do you have recommendations?
For example, read http://dev.clojure.org/jira/browse/CLJ-1936 — where
instrument caused a runtime failure due to lack of
test.check in your project’s dependencies.