Fork me on GitHub
#clojure
<
2019-01-23
>
noisesmith00:01:16

or if you just want to pick a specific result type: (into [] (map f) coll) etc.

caleb.macdonaldblack00:01:20

@noisesmith I've also been using vec quite a bit.

noisesmith00:01:44

the difference here is into doesn't need to build a lazy-seq, as it uses the transducing arity of the collection functions

noisesmith00:01:11

and it can use #{} or clojure.lang.PersistentQueue/EMPTY or {} instead of []

hiredman00:01:17

why do you need vectors?

caleb.macdonaldblack00:01:37

A have dynamic tabular data

caleb.macdonaldblack00:01:02

I don't know how many rows or columns I might have

caleb.macdonaldblack00:01:14

So I'm accessing cells in this data by x and y index

hiredman00:01:13

in broad strokes, lazy seqs can to some extent amortize the cost of traversals by being lazy so maybe you do a bunch of mapping opperations and only force them at the end, if you always concretely constructing vectors you lose that

caleb.macdonaldblack00:01:47

So I should probably just convert to vec in the final step?

caleb.macdonaldblack00:01:58

Or can I avoid vectors entirely here?

noisesmith00:01:03

it depends on the operations you are doing

šŸ‘ 5
hiredman00:01:04

hard to say

šŸ‘ 5
hiredman00:01:53

I might look at another representation too, maybe {[x y] data}, depending on what operations you are doing

hiredman00:01:30

if you can describe your transformations as a transducer you pass to into, that is even better than lazy seqs

hmaurer00:01:52

Hello! Quick q: is there a nice way in clojure to do a few if-let / if / let in a row (nested), but have them all branch out to the same fallback? For example when signing in a user you might want to fetch a user account (`if-let`), then check the password, etc, but if at any point the condition fails you want to branch out to some error message

noprompt02:01:20

You might have a look at a library Iā€™ve been working on which has pattern matcher designed to make this sort of thing easier to read without sacrificing (much) performance šŸ‘‰ https://github.com/noprompt/meander

(require '[meander.match.alpha :as r.match])

(defn find-password [data]
  (r.match/find data
    ;; Only binds ?password if data contains a :user key which points
    ;; to a map that has a :password key points to a string.
    {:user {:password (pred string? ?password)}}
    [:okay ?password]

    ?_
    [:nope]))

(find-password {:user {:password "password"}})
;; => 
[:okay "password"]

(find-password {:user {:password :wrong}})
;; => 
[:nope]

(find-password {:user {}})
;; => 
[:nope]

(find-password {})
;; => 
[:nope]

jumpnbrownweasel03:01:36

meander looks really awesome, i intend to find some time to try it soon

seancorfield00:01:58

@hmaurer If none of the "success" expressions can produce nil, you can always wrap the whole in (or ... (my-fall-back))

seancorfield00:01:20

(and use when/`when-let`)

seancorfield00:01:44

Also, I'd say that if you have a long enough chain of conditionals, you probably need to refactor it into smaller functions anyway (which then become a bit easier to chain together with or šŸ™‚ )

seancorfield00:01:54

(or threading or whatever)

mike_ananev00:01:00

@hmaurer hi. try these two different macros

hmaurer01:01:50

Thank you!

mv02:01:15

Can someone help me decipher one of the new clojure error messages? Itā€™s this:

{:type clojure.lang.Compiler$CompilerException
   :message Syntax error compiling at (plus_one_api/server.clj:38:1).
   :data #:clojure.error{:phase :compile-syntax-check, :line 38, :column 1, :source plus_one_api/server.clj}
   :at [clojure.lang.Compiler load Compiler.java 7647]}
  {:type java.lang.ClassNotFoundException
   :message clojure.spec
   :at [java.net.URLClassLoader findClass URLClassLoader.java 466]}]
 :trace

mv02:01:53

Does this mean that clojure.spec is missing? I looked at line 38 in server.clj, and it is a comment. Not a spec related comment

noprompt02:01:20

You might have a look at a library Iā€™ve been working on which has pattern matcher designed to make this sort of thing easier to read without sacrificing (much) performance šŸ‘‰ https://github.com/noprompt/meander

(require '[meander.match.alpha :as r.match])

(defn find-password [data]
  (r.match/find data
    ;; Only binds ?password if data contains a :user key which points
    ;; to a map that has a :password key points to a string.
    {:user {:password (pred string? ?password)}}
    [:okay ?password]

    ?_
    [:nope]))

(find-password {:user {:password "password"}})
;; => 
[:okay "password"]

(find-password {:user {:password :wrong}})
;; => 
[:nope]

(find-password {:user {}})
;; => 
[:nope]

(find-password {})
;; => 
[:nope]

mv02:01:29

This is a brand new Vase application

noprompt02:01:57

Sorry! I just Spectered the channel and didnā€™t mean to. šŸ˜­

noprompt02:01:12

Err, jQueried it.

noprompt02:01:54

Please donā€™t send me hate mail. šŸ˜†

andy.fingerhut03:01:53

@mv Is there any mention of the Java class java.net.URLClassLoader and/or the method findClass in that file? If so, note that findClass is a method, not a class. If there is an import statement that contains "java.net.URLClassLoader findClass", perhaps it should be changed to "http://java.net URLClassLoader"

andy.fingerhut03:01:50

The exception is a ClassNotFoundException, and since findClass is a method name, not a class name, that led to my questions above.

mv05:01:06

Nothing I found. Did clojure.spec exist under a different name at some point? Is this a version issue?

andy.fingerhut05:01:39

I do not see any mention of clojure.spec, or anything that I know to be related to clojure.spec, in the error messages you sent. What makes you believe it has something to do with clojure.spec?

dhruv104:01:07

hello, i am using kafka consumer in clojure and i keep seeing tons of these logs printed to screen: DEBUG org.apache.kafka.clients.consumer.internals.ConsumerCoordinator - Group some-group committed offset 8 for partition test-0 there are thousands of these, any one know how to turn them off?

dhruv104:01:00

settings i've tried: log4j.properties in resources folder

log4j.rootLogger=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n

log4j.logger.org.apache.kafka.streams=WARN
log4j.additivity.org.apache.kafka.streams=false
also
(set-logger! :level :warn
             :additivity false
             :pattern "%p - %m%n"
             :filter (constantly true))

dhruv104:01:03

i was able to solve this by adding a logback.xml file to my project

lepistane13:01:28

This might be stupid question but is there a way to process huge binary files/streams lazily? or partially ? or in chunks? and to save those parts/chunks to a file until stream is empty? I need to save big binary data to a file system without realizing whole stream in memory/heap. What i imagine is i have a reference to big input stream in java which i will use in clojure code as input stream which will take lets say 50mb > save to file take another 50 > save to file do this until stream is empty i am doing this ( input (java.io.FileOutputStream. (.getAbsolutePath tmp-file))) but i am not sure if it's what i am looking for

dominicm15:01:23

I think it copy does what you want, in 2mb chunks. It's pretty efficient.

Alex Miller (Clojure team)13:01:29

the Java channel APIs are probably the most efficient way to do stuff like this - Iā€™d just google up the best way to do it in Java, and then do the same via interop

šŸ‘ 5
borkdude16:01:57

Could the persistent data structures in Clojure be made as performant in idiomatic Clojure instead of Java?

john18:01:42

I believe Rich has intimated in the past that it could be done, but the payoff wasn't clear. FWIW, I believe CLJS's data structures are within an order of magnitude performance of CLJ's and they're implemented in CLJS. Not sure if the performance difference is between js's vm and JVM, or between CLJS and CLJ though.

mkvlr20:01:25

we should port clojurescript to graal/truffle and find out

borkdude20:01:12

well, since the code in clojurescript is ā€œpureā€ clojure, it shouldnā€™t be too hard to port it to .cljc, so you can run them in the JVM

mkvlr20:01:09

:thinking_face:

mkvlr20:01:30

can you recommend a resource about how clojurescript bootstraps itself?

borkdude20:01:24

I donā€™t know that much about it. Personally I would start reading the source code.

mkvlr20:01:58

yeah, I'm doing that, still can't comprehend how little js there is in the repo, just a handful of boostrap files in https://github.com/clojure/clojurescript/tree/master/src/main/cljs/cljs

mkvlr20:01:24

the js* calls i mean

borkdude20:01:00

I was wrong about that probably

mkvlr20:01:45

but the emit link is helpful. I had searched for this without success a few times, thanks!

john21:01:47

Well, cljs's persistent data structures are built on js's arrays, which are pretty semantically close to java's imo. So it shouldn't be too hard to port them over

borkdude17:01:44

yeah, thatā€™s why Iā€™m wondering šŸ™‚

borkdude17:01:58

why does pop throw for empty collections, but not for an empty queue?

jsa-aerial17:01:08

Hmmm, don't see a more specific channel, so asking here. Has anyone used bidi https://github.com/juxt/bidi with http-kit? The claim is it is compatible with http-kit, but not sure how to use it via http-kit/run-server

nwjsmith18:01:14

@jsa-aerial might be worth posting in #juxt

jsa-aerial20:01:55

Thanks - you were correct, answer given there

mseddon18:01:50

Does anyone know how to correctly escape arguments to lein under windows powershell? I've tried variously lein update-in :dependencies conj "[nrepl \`"0.5.3\``"]" -- repl`` and lein update-in :dependencies conj '[nrepl "0.5.3"]' -- repl, but the first just prints the help banner and the latter blows up in the lisp reader claiming 0.5.3 isn't a valid number šŸ™‚

mseddon18:01:57

also I apparently can't escape backticks in slack markdown correctly, so that is compounding the issue...

dpsutton18:01:12

if you have emacs and cider, you could jack in in a project and then check the *Messages* buffer which will have the lein invocation that CIDER uses. it has some escaped arguments there.

mseddon18:01:46

yeah, looked at that already, but it appears that cider is invoking it some other way, to complicate matters :S

mseddon18:01:19

unfortunately I want to invoke lein from powershell, rather than from cmd.exe, which I (think) is approximately what is happening. Either way, cider prints :dependencies conj ^"[nrepl \^"0.5.3\^"]^" which is definitely not right

mseddon19:01:20

It seems the batch file works differently and can be sanely escaped. I suspect also that is why emacs works, since it isn't powershell aware iiuc.