Fork me on GitHub
#clojure
<
2016-02-09
>
reefersleep07:02:49

Hey @meow, thanks for the review! simple_smile

reefersleep07:02:38

I'll keep the loop/recur thing in mind. (I'm inclined to avoid it myself just out of its verbosity : )

reefersleep07:02:36

And it's good to hear that I'm on the right path simple_smile

dm307:02:21

loop/recur is great if you want to squeeze out some more performance

dm307:02:26

or when transcribing some imperative algorithm (with volatiles)

dm307:02:35

not so much otherwise

sander07:02:57

why not recommend loop/recur for slower code as well? because recursive fns are easier to debug? or, because lazy seqs are more clojure-like?

dm307:02:31

when coming from a non-functional background people will reach for loop/recur instead of reduce most of the time

dm307:02:46

(in my experience, at least)

dm307:02:12

obviously, if you have a recursive algorithm you should use whatever suits best

cl0jurian07:02:14

hi there I'm in a little problem regarding selmer template library. not sure this topic is related here. Highly appropriated someone give a hint about this. http://stackoverflow.com/questions/35285822/how-to-add-a-dynamically-concatenated-file-name-for-include-tag-in-selmer-clo

gv12:02:19

Hello, is there a maintained tool library to facilitate usage of JavaFX in Clojure?

jaen12:02:06

Can't tell you which is better though, didn't use any of those, you'd have to check them out on your own

gv12:02:38

ok thanks. apart from the first one this is what google told me already 😉

reefersleep12:02:19

I hear you, @dm3, and I always keep this in mind. So far, I haven't had troubles with performance.

reefersleep12:02:42

@sander: Like I said, loop/recur can be verbose, and that can be reason enough in itself not to use it. It is for me simple_smile I don't any other explicit arguments against it.

artemyarulin12:02:32

Hi, what it the right approach to test async code with clojure? I’m not using core.async, I just have a small function which calls a callback at the end. Is there anything for that? Didn’t find anything in clojure.test

artemyarulin12:02:38

oh, maybe I should ask it in testing channel

artemyarulin13:02:37

ok, promise is a key - I can wrap callback with it and block until promise is fulfilled

jcromartie14:02:15

what's the hivemind's opinion on dynamically def'ing vars, say, in a loop?

jcromartie14:02:56

like, (doseq [[k v] some-map] (eval `(def k v)))

dm314:02:32

fine, if you know what you're doing simple_smile

meow14:02:15

That looks evil and sometimes evil is good - but why do you need it?

jcromartie14:02:42

we have a namespace that deals with recognized MIME types

jcromartie14:02:08

but I'm thinking I might be doing it wrong

meow14:02:22

Perhaps a macro.

meow14:02:33

rather than eval

jcromartie14:02:34

a big map of keywords to mime types and other info

jcromartie14:02:06

it is hard to infer what's there when looking at the code

meow14:02:22

eval is evil

dm314:02:00

I don't think there would be any problems with eval in this case though

dm314:02:07

except maybe for readability

jcromartie14:02:36

eval also confuses my editor

meow14:02:55

I agree - at least eval only works on forms and not text - so only a little evil

meow14:02:01

and evil is good

meow14:02:31

👿 😎 😇

meow14:02:36

¯\(ツ)

jcromartie14:02:43

well, with read-string it does

bronsa14:02:57

@jcromartie: you don't need eval+`def`, you can intern vars at runtime with intern

bronsa14:02:36

but I'd rather dispatch on a map of k->function than intern stuff at runtime

jcromartie15:02:35

ah, intern, good idea

jcromartie15:02:10

well, I like the fact that if I mess up a var it gives me an error at load time

jcromartie15:02:24

rather than waiting until much later to find out that the keyword I used is not recognized

profil15:02:51

Read through this article from the JUXT blog, https://blog.juxt.pro/posts/xpath-in-transducers.html , and wondering, how does one implement the descendants as a transducer? Is it recursive?

arijun15:02:03

Am I doing something dumb? I see in printed in the repl, but not when running the file separately.

(defn try-ssh []
  (println "out")
  (for [machine machines]
    (println "in")))

profil15:02:43

@arijun: is machines defined?

arijun15:02:03

(println machines) yields the same results in both places

pbostrom15:02:07

use doseq instead

arijun15:02:25

oh that makes sense

arijun15:02:32

yup, that did it, thanks!

arijun16:02:40

with core.async, what's the standard way to wait for all of my workers to finish processing my task queue?

PB16:02:56

Hey guys… Is this a bug in clojure? https://www.refheap.com/114616

meow16:02:31

Very interesting example. Not sure about that one.

PB16:02:52

@meow: It seems to be something to do with map and apply

jr16:02:52

map is lazy

solicode16:02:56

I’m guessing laziness is causing it? Try wrapping it in doall

jr16:02:01

(doall (map

jr16:02:11

before leaving the with-redefs closure

PB16:02:18

@jr that returns the correct response

PB16:02:38

Still seems like a bug to me

meow16:02:41

lazy can be evil

meow16:02:10

there is always a price to pay with lazy

PB16:02:45

So help me understand why the laziness would result in it using the un-redef’d version of the fn please

meow16:02:58

clojure is dynamic

meow16:02:25

that's how lazy works

meow16:02:44

same thing happens with side effects - they don't occur

meow16:02:05

lazy implies nothing happening

PB16:02:29

They do when it’s evaluating. I figured the fn that’s printing this into my repl would be evaluating it?

jr16:02:43

from the with-redefs docs: > After the body is executed, the root values of all the Vars will be set back to their old values.

PB16:02:17

That’s an answer I can get down with

jr16:02:19

the repl is printing the return value of that body after the vars are set back

PB16:02:25

That makes sense

wunsch17:02:14

Hi there, qq. If i :require a namespace :as something, I don’t seem to be able to use things like ns-publics on that symbol or var

wunsch17:02:30

What am I missing?

tbaldridge17:02:58

@wunsch: Clojure doesn't work like Python where imported vars are brought into the current namespace

tbaldridge17:02:08

instead they are added to a alias list of sorts

wunsch17:02:05

@tbaldridge: is there a way to expand that alias?

tbaldridge17:02:17

You can use https://clojuredocs.org/clojure.core/ns-aliases to look up the list of required/alised namespaces

tbaldridge17:02:29

give me a sec to look up if there's something like that for vars

wunsch17:02:47

okay awesome

wunsch17:02:21

thanks tbaldridge! looks like I can also do something like (get (ns-aliases *ns*) :alias)

tbaldridge17:02:32

yep, that should work

wunsch17:02:15

cool thank you!

jcromartie18:02:12

I was just thinking: could memoize be a security risk?

jcromartie18:02:31

in the form of a Denial of Service

jcromartie18:02:24

if you memoized something based on user input, an attacker could send enough different data to OOM your JVM?

solicode18:02:56

@jcromartie: cache eviction is not part of memoize, so yes, I’d think that would be a concern if it’s based on user input.

pbostrom18:02:23

yes in general you want the set of inputs to a memoized fn to be bounded

jcromartie18:02:27

I don't think it would ever actually happen, but yeah

jcromartie18:02:32

in this case it's HTTP header values

meow18:02:36

at the least you can consume a lot of memory if not careful

jcromartie18:02:57

I'm starting to prefer cond over defmulti and defprotocol wherever possible

akiva18:02:32

I only use cond when it’s returning something simple. If there’s any complexity to processing, I stick with defmulti.

jcromartie18:02:10

I suppose most of the time I am returning something simple

jcromartie18:02:18

or it's just calling some other function in turn

akiva18:02:28

I think there’s some added speed/efficiency with defmulti over cond but I could be wrong.

solicode18:02:36

Also the whole open vs closed set thing.

solicode18:02:58

When writing libraries where extension is possible, case and cond are off the table

solicode18:02:02

But otherwise it’s fine

jcromartie18:02:12

interesting, thanks

jcromartie18:02:25

so, multimethods are faster than cond

solicode18:02:48

I think cond is generally faster

bronsa18:02:51

not necessarily

bronsa18:02:45

cond is always linear, defmulti is ~constant time dispatch after caching

timvisher18:02:15

has anyone successfully made a TLSv1.1 request using clj-http on java 7?

solicode18:02:25

So case would be the better comparison since it also caches, right? If applicable that is

bronsa18:02:55

case doesn't cache, it does constant time switches on the values/hashes

solicode18:02:58

Ah, I got that from the article. "Because both case and multimethods use a cache […]"

bronsa18:02:22

well, that's not true

solicode18:02:58

Okay, good to know. I looked up the docs for case and it states what you’re saying

akiva18:02:04

case also doesn’t do any sort of evaluation.

bronsa18:02:11

multimethods and protocols do, case doesn't

akiva19:02:25

Meanwhile, I’m having a bit of trouble intelligently walking a tree-map. I need to hit every node, and based on either the name of the key or the type of the value, I need to modify the value (e.g., convert a val's vector of strings to a vector of keywords or if the key is :whatever convert its val to a keyword). I’ve been messing with clojure.walk but I’m kind of spinning my wheels here and I don’t want to waste too much time on this or re-invent the wheel. Any advice?

meow19:02:30

are you using one of the walk functions akiva

meow19:02:57

oops, you said you were

akiva19:02:02

Aye, cap’n.

meow19:02:16

code example?

akiva19:02:41

Hold on a bit. Let me see if I can get it back to a sane state.

meow19:02:06

I don't know about sane states.

jotaro20:02:11

hi guys, Is there any book about memory usage optimaztion in clojure ?

meow20:02:48

No book that I know of, but it might be covered in one of the Clojure books. Most don't go into that topic in much detail.

meow20:02:11

What are your concerns, or what are you hoping to accomplish?

Chris O’Donnell20:02:50

Does anyone have experience integrating sente and component? I'm at a loss as to how to inject dependencies into my message handler.

meow20:02:21

#C0GQAAKA9

meow20:02:08

might also ask there

Chris O’Donnell20:02:11

good call, thanks

jaen20:02:42

@codonnell: don't have much time to explain now, but that's how I do it - https://gist.github.com/jaen/cc8600e682eb65ec4a55

jaen20:02:52

If you can understand that it might be helpful

Chris O’Donnell20:02:31

I'll take a look! At the least, it's always good to practice reading other peoples' code.

jaen20:02:57

I hope you won't develop any terminal disease from that, its' pretty ugly.

jaen20:02:28

But basically, this component takes the components it depends on, filters out those that have a AsyncHandlerProvider protocol that has a method which returns map of form {dispatch-value handler} and then shoves that into a multimethod.

jaen20:02:42

A pretty funny multimethod, because it's not defmulti'd

Chris O’Donnell20:02:43

I'll let you know if I have questions. And if you can't get back for a while, no worries.

Chris O’Donnell20:02:00

I really appreciate any kind of lead on how to make this work.

timvisher20:02:03

how do i use something like current_timestamp() in clojure.java.jdbc/insert!?

timvisher20:02:28

(obviously i can (let [now …] …) but i want it to use the DB feature)

jcromartie21:02:53

isn't that just SQL?