Fork me on GitHub
#clojure
<
2018-06-06
>
lwhorton01:06:23

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. parens forever parrot

48
parens 4
seancorfield04:06:40

@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.

seancorfield05:06:31

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!

🙂 12
4
Sushma05:06:52

In clojure How can I set the parquet compression algorithm to gzip?

Sushma06:06:17

Is it by default gzip?

the2bears06:06:46

What are you trying to do?

metacritical09:06:32

@nayudu.sushma Are you trying string compression? as in RLE or something ?

ben.mumford13:06:16

hi all, i'm trying to hash a clojure map such that regardless of the order of the keys the hash is the same

ben.mumford13:06:19

(-> {} (assoc :a 1) (assoc :c 2)) ;; {:a 1 :c 2} (-> {} (assoc :c 2) (assoc :a 1)) ;; {:c 2 :a 1}

dpsutton13:06:53

(= (-> {} (assoc :a 1) (assoc :b 2) hash) (-> {} (assoc :b 2) (assoc :a 1) hash)) is true

ben.mumford14:06:57

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

ben.mumford14:06:04

i was afraid i might have to recursively convert to sorted maps, json-ify then use a string->hash sha-256 thingy

dpsutton14:06:22

(let [size  1e7
      map1 (into {} (for [x (range size)] [x x]))
      map2 (into {} (for [x (range size)] [x x]))]
  (= (hash map1) (hash map2)))
true

dpsutton14:06:11

millions of entries in the map or millions of maps?

ben.mumford14:06:19

millions of maps 🙂

ben.mumford14:06:47

postgres is freaking out that the maps are too big to calculate an index for them

ben.mumford14:06:04

so i need to calculate a hash for it on the way in and then index against that

dpsutton14:06:10

ah. well you are outside of my wheelhouse 🙂

ben.mumford14:06:36

thanks anyway bud

dpsutton14:06:55

could you have each map explicitly assoc its hash value on a key? and then index on this?

dpsutton14:06:13

some book keeping involved but this would keep postgres and clojure talking about the same things at least

ben.mumford14:06:45

that's pretty much what i'm planning (except a separate column for the hash)

dpsutton14:06:21

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

dpsutton14:06:40

also, andy fingerhut on here is quite interested in "equality" in clojure so he might be a good person to chat with

ben.mumford14:06:56

cool, i'll look him up

ben.mumford14:06:04

have a nice day

dpsutton13:06:58

you're already covered

dpsutton13:06:24

note the hash calls on each

logistark13:06:43

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

logistark13:06:29

Can anyone check this behaviour? Or have anyone encountered before?

metacritical13:06:43

(= 5)will return true!

dpsutton13:06:11

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"}

metacritical13:06:59

(is (= 5) nil)will also return true.

logistark14:06:24

not in my machine

metacritical14:06:33

What you need is (is (= 5 (other-equality-condition))

logistark14:06:48

(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

metacritical14:06:18

@jimenezsaezjoseantoni (require '[clojure.test :as test]) (test/is (= 5) nil)`

logistark14:06:50

(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

metacritical14:06:03

@jimenezsaezjoseantoni Interesting results, not sure why that is the case!

dpsutton14:06:43

can you just eval (= 5) without any test assertion?

logistark14:06:56

that will return true

logistark14:06:15

user=> (= 5)
true

logistark14:06:30

i think the problem is realted to is macro

metacritical14:06:07

This should mostly work (is (= 5 (other-equality-condition))

logistark14:06:30

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)))

logistark14:06:42

Both expression are going to give true

logistark14:06:49

even when you made a mistake

logistark14:06:59

in the worse case you have a false true

dpsutton14:06:51

oh. well, yeah you have to make sure you test what you want to test

logistark14:06:40

I am sure, but what if by mistake you don't notice this, the test will pas silently

metacritical14:06:26

@jimenezsaezjoseantoni you need two separate is to test two separate expressions. The usual syntax is (is (predicate test expr)) `

dpsutton14:06:24

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

dpsutton14:06:52

(is (consistent (user-counts info) 5))) or something like that

metacritical14:06:09

it can be 1 arity also for instance (is (keyword? expr))

metacritical14:06:57

Is just exists to have better reading tests and automation.

dpsutton14:06:06

that looks like a feature for you then, right? don't you want to prevent the testing of (= 4)?

dpsutton14:06:21

(throw (Exception. "= expects more than one argument")) i'm surprised this didn't show up then

tvalerio14:06:46

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)

tvalerio14:06:24

I have another project with clojure and datomic where I use edn files but when it comes to postgres I found nothing 😕

skrat14:06:56

@dominicm see above, it's in the snippet, a call to s/valid?

dominicm15:06:23

Just wanted to make sure 🙂

dominicm15:06:21

@skrat the error could be in :survey/status?

skrat15:06:41

@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

Denis G15:06:13

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.

dominicm15:06:12

@denisgrebennicov you should call seq on the string before passing it in

theeternalpulse16:06:26

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.

eggsyntax16:06:33

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

theeternalpulse17:06:38

I've been trying out the repl, haven't used the send-to functions of cider will check those out.

theeternalpulse18:06:31

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

Denis G16:06:20

Still confused, why something like this doesn’t work

(s/def ::base #"[a-zA-Z]")
(s/conform ::base (seq "a"))

Denis G16:06:53

tried with and without quotes for regex

Denis G16:06:55

write not I get

Denis G16:06:03

java.util.regex.Pattern cannot be cast to clojure.lang.IFn

hiredman16:06:17

why do you think it would work?

hiredman16:06:33

spec is not built around regexes, it is built around predicates

hiredman16:06:37

none of the spec docs or examples indicate you can use a regex

hiredman16:06:06

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

Denis G16:06:19

@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.

theeternalpulse18:06:38

maybe

(s/def ::test #(some #{\a \b} %))
(s/conform ::test (seq "a"))

theeternalpulse18:06:01

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

eggsyntax16:06:57

@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

eggsyntax16:06:43

(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)

hiredman16:06:20

(fn [letter] (fn [input] (= letter input)))

hiredman16:06:35

or just (partial = letter)

hiredman16:06:44

or #{letter}

hiredman16:06:12

why aren't you looking at instaparse?

hiredman16:06:41

instaparse is actually built as a parser of strings, and will let you define terminals as regexs

hiredman16:06:45

if you want to match any character char?is the predicate

hiredman16:06:37

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

dadair17:06:41

Use clojure.test fixtures to insert dynamic data?

dadair17:06:29

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?

tvalerio17:06:14

hm, I’ll take a look into that

Alex Miller (Clojure team)18:06:24

@denisgrebennicov I’ll second @hiredman - if you want to parse, use instaparse, not spec

Denis G22:06:23

I was trying to learn spec while solving my problem, therefore didn’t want to use instaparse to do this job

Denis G23:06:21

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

aengelberg19:06:09

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

🍻 28
8
korny19:06:08

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?

korny19:06:21

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

rutledgepaulv19:06:14

distinct-by is something I’ve often sorely missed in core

rutledgepaulv19:06:40

(distinct-by :key ordered-sequence)

korny19:06:06

nice - at least I can steal that code 🙂

rutledgepaulv19:06:36

it’s just a knock-off of distinct if you view the clojure source 😛

rutledgepaulv19:06:41

but nice since it returns a transducer and all

korny19:06:25

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.

korny19:06:48

(and distinct loses any benefits of knowing the sequence is sorted)

rutledgepaulv19:06:18

deduplicate is available if you just want to drop contiguous entries

rutledgepaulv19:06:32

but I wouldn’t assume that checking a key is more efficient than the whole map

rutledgepaulv19:06:53

persistent data structures make whole object comparisons pretty cheap afaik

korny21:06:34

@rutledgepaulv thanks for dedupe. Sigh. My ability to search the cheat-sheet is pretty poor tonight, it seems.

spieden21:06:08

any timeline on the prem -> cloud migration tool?

spieden21:06:31

> If you are working on committed code with no local deps you will get a stable revision named after your commit.

spieden21:06:39

what if the local deps are in the same git repo? ^^

spieden21:06:28

hah wrong channel

emccue22:06:53

Problem that knowing clojure solved for my java project

emccue22:06:16

We get events as xml passed through query parameters to a url

emccue22:06:57

and its involved xml too

emccue22:06:04

my god clojure saved my ass on parsing

jeremyraines22:06:10

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

jeremyraines22:06:24

I found someone having a similar issue with a sorted-map, but mine is not

andy.fingerhut22:06:04

@jeremyraines That sounds quite unusual to me. Could there be issues with non-ASCII characters being used in the keywords involved?

noisesmith22:06:12

if you literally mean print as, it could be ":foo"

jeremyraines22:06:39

i checked that it’s actually a keyword

noisesmith22:06:40

(and using prn instead of print / println will make that clear)

jeremyraines22:06:52

@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

andy.fingerhut22:06:52

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.

andy.fingerhut22:06:17

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

hiredman23:06:43

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

hiredman23:06:17

a map containing the string ":foo" as a key will println like {:foo 1} but prn like {":foo" 1}

hiredman23:06:38

csv-map looks pretty questionable if https://github.com/mihi-tr/csv-map is it

jeremyraines23:06:56

andy’s suggestion to map the chars of the (str kw) seems to reveal that it is a hidden character — thanks @andy.fingerhut

jeremyraines23:06:20

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

jeremyraines23:06:40

@hiredman yeah that’s the one

jeremyraines23:06:01

pretty light wrapper over clojure.core/parse-csv

hiredman23:06:23

there is no clojure.core/parse-csv

jeremyraines23:06:25

or rather clojure.csv

jeremyraines23:06:27

it was a Byte Order Mark, can be removed in Vim with :set nobomb