This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-06
Channels
- # beginners (137)
- # cider (60)
- # cljs-dev (52)
- # cljsrn (5)
- # clojars (15)
- # clojure (156)
- # clojure-brasil (1)
- # clojure-dev (7)
- # clojure-italy (13)
- # clojure-serbia (2)
- # clojure-spec (12)
- # clojure-uk (76)
- # clojurescript (129)
- # core-async (27)
- # core-typed (1)
- # cursive (3)
- # datomic (105)
- # devcards (39)
- # emacs (10)
- # figwheel (1)
- # fulcro (68)
- # graphql (6)
- # juxt (3)
- # klipse (85)
- # lein-figwheel (47)
- # leiningen (3)
- # midje (1)
- # mount (26)
- # off-topic (71)
- # om (4)
- # overtone (4)
- # parinfer (3)
- # pedestal (4)
- # portkey (37)
- # re-frame (37)
- # reagent (13)
- # reitit (3)
- # ring (1)
- # rum (5)
- # shadow-cljs (191)
- # spacemacs (35)
- # specter (26)
- # tools-deps (45)
- # vim (20)
thank you clojure for always trying to use data to solve problems. any time i have to go into another language i find myself reimplementing “data as a first class citizen” everywhere, and it saddens me. forever

@punit-naik That would be more on-topic in #aws but I don't know how active that channel is. Since the question isn't about Clojure, it doesn't belong in this channel -- #off-topic would be a safe place to ask, with plenty of people in it.
Public apology to @punit-naik for pushing him to other channels -- I totally missed he was asking about a specific Clojure library and thought he was asking about AWS Console stuff. My bad!
@nayudu.sushma Are you trying string compression? as in RLE or something ?
hi all, i'm trying to hash a clojure map such that regardless of the order of the keys the hash is the same
(-> {} (assoc :a 1) (assoc :c 2)) ;; {:a 1 :c 2} (-> {} (assoc :c 2) (assoc :a 1)) ;; {:c 2 :a 1}
any ideas?
(= (-> {} (assoc :a 1) (assoc :b 2) hash) (-> {} (assoc :b 2) (assoc :a 1) hash))
is true
hi @U11BV7MTK, i am expecting millions of these things and need the hash to not collide. i was hoping i could use a sha-256 hashing algorithm
i was afraid i might have to recursively convert to sorted maps, json-ify then use a string->hash sha-256 thingy
(let [size 1e7
map1 (into {} (for [x (range size)] [x x]))
map2 (into {} (for [x (range size)] [x x]))]
(= (hash map1) (hash map2)))
true
millions of maps 🙂
postgres is freaking out that the maps are too big to calculate an index for them
so i need to calculate a hash for it on the way in and then index against that
thanks anyway bud
could you have each map explicitly assoc its hash value on a key? and then index on this?
some book keeping involved but this would keep postgres and clojure talking about the same things at least
that's pretty much what i'm planning (except a separate column for the hash)
well this sounds like an interesting article about the pain and solutions. you should for sure type it up when you've got something cobbled together
also, andy fingerhut on here is quite interested in "equality" in clojure so he might be a good person to chat with
cool, i'll look him up
cheers pal
have a nice day
Hi, i have come with one issue on my test.
(clojure.test/is (= 5) {:test "fail"})
this expr on some machines return true
and in other returns error(= 5)
will return true!
tests normally return a good message about why they failed. if you are seeing a failure, let that bubble up rather than the uninformative override you've got with {:test "fail"}
(is (= 5) nil)
will also return true.
What you need is (is (= 5 (other-equality-condition))
(clojure.test/is (= 5) nil)
ERROR in () (form-init1777224899660398758.clj:1)
expected: (= 5)
actual:
clojure.core/eval core.clj: 3105
...
dev-platform/eval52764 REPL Input
java.lang.Exception: = expects more than one argument
nil
@jimenezsaezjoseantoni (require '[clojure.test :as test]) (test/is (= 5) nil)
`
(require '[clojure.test :as test]) (test/is (= 5) nil)
nil
ERROR in () (form-init1741981829714996247.clj:1)
expected: (= 5)
actual:
clojure.core/eval core.clj: 3105
...
dev-platform/eval52758 REPL Input
java.lang.Exception: = expects more than one argument
nil
@jimenezsaezjoseantoni Interesting results, not sure why that is the case!
This should mostly work (is (= 5 (other-equality-condition))
Yes, the problem for me is, that by mistake you write (is (= (large-expression-large-large)) (other-large-large-large-expression)) instead of (is (= (large-expression-large-large) (other-large-large-large-expression)))
I am sure, but what if by mistake you don't notice this, the test will pas silently
@jimenezsaezjoseantoni you need two separate is
to test two separate expressions. The usual syntax is (is (predicate test expr))
`
so one thing to do is not use =
but instead use a function that has a definite arity of two. so if you made the mistake it would error
it can be 1 arity also for instance (is (keyword? expr))
Is just exists to have better reading tests and automation.
that looks like a feature for you then, right? don't you want to prevent the testing of (= 4)
?
(throw (Exception. "= expects more than one argument"))
i'm surprised this didn't show up then
Is there a way to use datasets in clojure and postgres for tests with dynamic data? I managed to use xmls to populate the database but I was not able to use clojure functions in it to hava dynamic data (like today date for a column for example)
I have another project with clojure and datomic where I use edn files but when it comes to postgres I found nothing 😕
@dominicm thanks for looking, I found the issue, it was this AOT thing again, when the .clj and .class files in uberjar have the same timestamps
I’m working with spec right now. Want to catch/parse the value which ends with * (for my regex parser)
Currently something like this doesn’t work -> (s/cat :base ::base :star #"\*")
Any ideas? The regex matchign doesn’t seem to work and I don’t know how to make string match in spec.
@denisgrebennicov you should call seq
on the string before passing it in
See https://juxt.pro/blog/posts/parsing-with-clojure-spec.html and https://gist.github.com/thegeez/77aee6f0ebcf6a42aa7d893388502e40
I tend to use my emacs cider eval more than I use the repl buffer, is there any benefit to a workflow by using the repl in tandem with eval'ing in a buffer directly, or completely using the repl. I'm just not seeing it as convenient.
Stu Halloway has an interesting approach where he uses a scratch buffer & sends everything to the repl from there, and then saves the scratch buffers. That way he's got a durable record of everything he's ever done while developing. I don't use it myself, but it's a thought-provoking idea. Like you, I tend to do most stuff in-buffer, although depending what it is, I send a lot of stuff to the repl from a file buffer rather than evaling it inline. That way I've got a bit of a record of the current session, although I don't save them off. See https://vimeo.com/223309989
I've been trying out the repl, haven't used the send-to functions of cider will check those out.
I often just do inline #_(...
forms in my code and if I feel they are a particularly clever thing I try to save it in a sandbox project. I think I reach for those instead of just writing tests which is a habit I'm working on breaking
Still confused, why something like this doesn’t work
(s/def ::base #"[a-zA-Z]")
(s/conform ::base (seq "a"))
https://clojure.org/guides/spec#_entity_maps has maybe the closest example, it shows using a regex and re-matches to build a predicate for spec
@hiredman anyway. What I want is match only single letter. I don’t want s/* or s/+, just single one. Still confused on how to achieve that.
maybe
(s/def ::test #(some #{\a \b} %))
(s/conform ::test (seq "a"))
ah, actually not exactly what you want, but the predicate you return can do anything, so just imagine it being passed to it and have it return the truthy result you want in the case you're looking for
@denisgrebennicov in case it's unclear -- spec does use regular expressions (despite what @hiredman said above -- see https://clojure.org/guides/spec#_sequences ). But they're not regular expressions describing sequences of characters -- they're regular expressions describing data structures.
It's really confusing when you first encounter it, because most of us have only heard the term "regular expression" with reference to string regexes. If you're trying to do string regexes, look at clojure.core/re-find
and related functions.
https://clojuredocs.org/clojure.core/re-find
(it's possible I missed something in the thread and you really are trying to do something that requires instaparse, but at first glance it looks like you're looking for regular string regex)
instaparse is actually built as a parser of strings, and will let you define terminals as regexs
if you turn a string in to a seq of characters, you cannot use java regexes on them, because regexes only match strings, but spec can only do parsing kind of things on a string if you turn it in to a collection of characters
For example, you could parse the XML into a data structure, and transform it to have today’s date for certain fields prior to insertion using say clojure.jdbc within a clojure.test fixture?
@denisgrebennicov I’ll second @hiredman - if you want to parse, use instaparse, not spec
I was trying to learn spec while solving my problem, therefore didn’t want to use instaparse to do this job
I’ve decided to do that with spec after watching this video → https://www.youtube.com/watch?v=Rlu-X5AqWXw Where David Nolan showed, that it was possible to do that, on the example with Trees
I'm gonna submit a patch to Clojure spec that automatically calls (println "You should use instaparse")
whenever a regex spec is used to parse characters of a string
Hey folks - is there a quick way to de-duplicate a sequence by a (sorted) key?
e.g. given [{:key 'a' :data 'apple'} {:key 'a' :data 'apple'} {:key 'b' :data 'banana'}]
return a sequence of just the first and last (`apple` and banana
) hashes?
The only way I can think of to de-dupe a sequence is to put all the values in a set (or hash) but I want something that can work more simply on a sorted sequence
distinct-by
is something I’ve often sorely missed in core
(distinct-by :key ordered-sequence)
it’s just a knock-off of distinct if you view the clojure source 😛
but nice since it returns a transducer and all
I’d forgotten distinct
- that would probably work for me, though I worry a bit about how efficient it is. My non-unique entries are probably identical - I just assumed it’d be more efficient to compare keys than the whole object.
deduplicate is available if you just want to drop contiguous entries
dedupe*
but I wouldn’t assume that checking a key is more efficient than the whole map
persistent data structures make whole object comparisons pretty cheap afaik
@rutledgepaulv thanks for dedupe
. Sigh. My ability to search the cheat-sheet is pretty poor tonight, it seems.
> If you are working on committed code with no local deps you will get a stable revision named after your commit.
does anyone know of a reason why trying to key into a map with a known existing key (with value) would return nil? e.g. the map prints like {:foo 1 :bar 2}
but (:foo that-map)
evaluates to nil
I found someone having a similar issue with a sorted-map, but mine is not
@jeremyraines That sounds quite unusual to me. Could there be issues with non-ASCII characters being used in the keywords involved?
if you literally mean print as, it could be ":foo"
i checked that it’s actually a keyword
(and using prn instead of print / println will make that clear)
@andy.fingerhut I suspect this might be the case. It’s on a result of using the csv-map
library. But I’ve tried what I can think of to expose hidden characters, copied the whole file as plain text to a new file, etc
Maybe something like (map int (str <my-keyword-expr>)) on the one in the map, and the one you are trying to search for, would be a good way to find out if there are funny chars involved.
The issue you mention with not finding a key in a sorted map could be due to using a custom comparator function that is not correct. This article might help determine if this is the case: https://clojure.org/guides/comparators
or also check the type of the map, not just the printing, and call keys on the map, and check the type of all the keys
a map containing the string ":foo" as a key will println like {:foo 1} but prn like {":foo" 1}
csv-map looks pretty questionable if https://github.com/mihi-tr/csv-map is it
andy’s suggestion to map the chars of the (str kw) seems to reveal that it is a hidden character — thanks @andy.fingerhut
still a bit baffled because I’ve even tried deleting the header row and typing it out by hand, but this puts me on the right track I think
@hiredman yeah that’s the one
pretty light wrapper over clojure.core/parse-csv
or rather clojure.csv
https://github.com/mihi-tr/csv-map/blob/master/src/csv_map/core.clj this beyond light
it was a Byte Order Mark, can be removed in Vim with :set nobomb