Fork me on GitHub
#clojure
<
2016-12-05
>
aengelberg02:12:34

Via clojure.tools.namespace, is there a way to manually signal to the reloader what other namespaces my namespace depends on, rather than let it infer that from the ns form?

kzeidler04:12:42

@aengelberg: When you say "manually signal to the loader what other namespaces my namespace depends on," in what way are these manual signals different from arguments passed to the ns declaration via :require/etc?

kzeidler04:12:00

I'm currently exploring some of the features of clojure.tools.namespace as well

kzeidler04:12:20

(This is to say, I do not have all the answers :))

kzeidler06:12:25

When working with websockets, is it usually better to (A) define multiple event server-side handlers that all dispatch on a generic message from the client , or (B) emit different kinds of messages (e.g., a "login event message," a "form submit message") " and consume them with a single server-side handler?

bcbradley07:12:23

what is the most efficient way to test to see whether a set of keys exists within a map?

bcbradley07:12:54

i'll be doing this for every transforming function (will probably have around a thousand or so), 60 times a second in a game loop

bcbradley07:12:19

i can't be certain that a key isn't mapped to a value of boolean false

bcbradley07:12:59

currently i've got something like

(every? (partial contains? m) [:a :b :c])

cjmurphy08:12:56

Perhaps: (every? #{:a :b :c} (keys m))

dominicm08:12:41

You'd have to benchmark, but it's possible that some of the clojure.set functions applied to a set of the keys would be fast. Might be worth toying with reducers, to see if they're quicker than contains? For multiple lookups.

cjmurphy08:12:53

My example wrong, has to be other way round: (every? #{(keys m)} #{:a :b :c})

fellshard08:12:07

I don't think set literal is appropriate there

fellshard08:12:10

There ya go 🙂

dominicm08:12:22

Was confirming my suspicion :p

fellshard08:12:32

Best way to find out is to try!

bcbradley08:12:33

@cjmurphy that won't work for this map:

#{:boolean false :something nil}

cjmurphy09:12:17

Seems to work once set literals no longer used: (every? (set (keys {:boolean false :something nil})) #{:boolean :something})

rauh09:12:04

@bcbradley Sounds like speed might be important too. In that case I'd use reduce-kv instead of keys and set. Probably a bunch faster

bcbradley10:12:49

Why does

(subvec [1 2 3 4 5] 2 10)
return
[1 2 3 4 5]

olslash10:12:34

that throws for me

andfadeev10:12:35

it throws IndexOutOfBoundsException

hippo10:12:34

@andfadeev yep, for me too, i guess @bcbradley uses emacs and his cursor takes a wrong place for eval last expr.

bcbradley11:12:31

@hippo I don't use emacs but you've got the right idea. The error was caused by my cursor being in the wrong spot during a block evaluation.

dhruv13:12:55

anybody interested in web scraping? i've built a selenium based DSL in clojure, and i'm looking for beta testers before i publicise it on github!

tankthinks13:12:21

hey @dhruv, I have a side project that I could try it on

gerrit13:12:15

is there a way to alias the #_ reader macro to some other name, e.g., using tagged literals?

bronsa13:12:00

no, tagged literals have to return a value

gerrit14:12:25

pity. but thanks

roelofw14:12:10

Does clojure have a library I can use for pagination ?

dominicm14:12:27

@roelofw what would this library do?

roelofw14:12:28

take care that for example I can have 10 pages of 10 articles and that all pages have a link so I can browse between the pages

dominicm14:12:02

@roelofw so you have a list of 100 articles, and you want a function that will return a slice of 10 of them, and then choose which slice you want?

roelofw14:12:50

I think you wrote it out better then me

martinklepsch14:12:49

@mpenet checkmate looks nice 👍

dominicm14:12:12

@roelofw no library needed. Look at partition-all

mpenet14:12:36

@martinklepsch there are already tons of libs like this, but they all took a weird direction imho

martinklepsch14:12:40

@mpenet yeah seen plenty, what I like about yours is that I can read and understand it in 10min 😄

mpenet14:12:55

yeah, I am too old for more than 1 page of code 😛

dominicm14:12:21

I like the full conditional restart system, used to be called ribol

roelofw14:12:07

@dominicm thanks for the pointer

borkdude15:12:49

Didn’t know about the first way to do it. Second is still shorter.

(use 'clojure.pprint)
(use '[ :as io])
(with-open [w (io/writer "/tmp/output.edn")]
  (write obj
         :stream w
         :pretty true))

;; or

(spit "/tmp/output.edn" (with-out-str (pprint obj)))

ska15:12:43

Has anyone ever tried to read an EDN file which contains a BOM? Is that supposed to work? I just bumped into that.

pesterhazy15:12:40

does it work if you slurp first?

dominicm15:12:50

What's a BOM?

ska15:12:38

@domincm byte-order-mark

ska15:12:54

@pesterhazy I am just using edn/read on a io/reader where I am not defining an encoding. Do I have to?

ska15:12:10

@borkdude Is that code I can look at somewhere?

pesterhazy15:12:48

@ska, I'd try doing (-> file slurp edn/read) to see if that works with such a file

borkdude15:12:45

oh sorry, BOM, no

borkdude15:12:04

I thought you meant the eof marker, my bad 😉

ska15:12:51

@pesterhazy funny thing is, I can read the EDN alright but when I try to create a seq of the keys of it I get a "java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol"

pesterhazy15:12:21

try wrapping the reading in doall

ska15:12:19

Ah, getting closer. edn/read just returns an empty map right now. Still at repro stage, did not try your suggestion, yet.

ska15:12:22

No thanks. I'll just document that this is not allowed. shudder

m3nthal15:12:07

I tested the function inside the 'fold' on a sample of 20 entries after the filter and it works

fellshard15:12:08

Is fold eager or lazy?

m3nthal15:12:43

@fellshard sorry, but I don't know how to answer your question

fellshard15:12:55

I know what you're solving (hi, fellow Advent of Code player!) and you'll need something lazy like reductions 🙂

m3nthal15:12:02

I guess it is not, since it is from clojure.core.reducers

fellshard15:12:48

For this problem in particular, you'll really want laziness as long as you can manage

fellshard15:12:09

Because those MD5 hashes are relatively slow to calculate

fellshard15:12:48

Looks like all of reducers is made for eager contexts...

fellshard15:12:30

I have yet to work with the library, though, so not too familiar.

fellshard16:12:33

Given it's supposed to be used in similar contexts to parallel distributed map-reduce, it wouldn't be very practical for these to be lazy...

fellshard16:12:34

Try using regular map, filter, and replace fold with reductions to see what happens.

m3nthal16:12:26

@fellshard thank you, I will try to find the answer in the current library, if not, I will use map/filter/reductions from core

poooogles16:12:44

@fellshard oh amazing, didn't know advent of code was on again 😄

fellshard16:12:56

Jump on it! #adventofcode

poooogles16:12:00

there goes my afternoon of work.

roelofw16:12:23

any selmer expert here ?

fellshard17:12:43

Nice! And yeah, finally realized the obvious - reduce or fold alone are always going to be eager, since they're trying to take an entire sequence down to a single value; you can't finish that computation without reaching the end of the list. Hence the nicety of reductions. 🙂

fellshard17:12:32

Cool Clojure editor ideas: if functions that are lazy mark that fact in their metadata, an editor could highlight when you are likely making transitions between lazy and eager. Hmm....

agile_geek17:12:34

@fellshard I have same issue. Clojure has conventions and special forms that make state change explicit, e.g. swap! on an atom or @state to deref something, but it's not obvious when fn's process lazily or eagerly. As most are lazy perhaps the editors should highlight the eager evaluations instead?

lvh17:12:32

Do I need to do anything besides include the dependency for https://github.com/fzakaria/slf4j-timbre to work? I added the dependency, but am still getting

log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See  for more info.

lvh17:12:15

of course, I stare at this for 20 minutes and only figure it out when I ask someone else

lvh17:12:19

🦆

lvh17:12:32

(answer: slf4j is not log4j)

lvh17:12:56

Hey I just got back from Conj and weather delayed my plane for a bunch so I didn’t make it to bed until 3AM; gimme a break

dpsutton17:12:36

your talk was excellent by the way

hlolli20:12:18

I remember reading clojure applied and at one point they talked about the printing of object types so: #object[Object object] could be #<myType>. If my memory is not wrong, can someone send me an article/blog that covers this?

lvh20:12:53

@dpsutton @richiardiandrea Thanks! Glad you liked it 🙂

hlolli20:12:57

thanks @pesterhazy this will put me on the right track.

hlolli20:12:27

even better, you get tagged literal

shaun-mahood21:12:32

After watching the talks by Rich and Stu, I feel like I should try to actually namespace things correctly. Does anyone know of any good resources on how I should be doing this (not the technical how necessarily, more so that my projects will work nicely with everyone else).

roelofw21:12:36

someone here who knows how to deal with a background-image in css with luminus. I did now : background: url('img/old-wall.jpg') no-repeat center center fixed; but no background-image. the image is in resources/public/img directory

hlolli21:12:43

@roelofw 1. can you open the image via localhost:XXXX/img/old-wall.jpg? 2. are you opening a subpage? (in which case '/img/old-wall.jpg') would be needed for relative path. otherwise there exists #css group.

roelofw21:12:45

@hlolli , yes, then I see the image

hlolli21:12:26

then I guess that dom element you are targeting is not being displayed or other css rules are overwriting. You are welcome to send me your css and html in pm.

roelofw21:12:58

got a lead : on ff I see this error message : http://localhost:3000/css/img/old-wall

roelofw21:12:21

so somewhere the css directory is included

roelofw21:12:52

No idea why and where luminus do that

hlolli21:12:08

oh, you need to do background: url('../img/old-wall.jpg') no-repeat center center fixed; I think or simply start with slash '/img/old-wall.jpg' that way it should ignore the css directory in which the stylesheet is located.

dpsutton21:12:08

haha not very useful for you to post a link to localhost

dpsutton21:12:34

just put a slash at the beginning of img

roelofw22:12:18

I know that , I did that because I saw a css part where it was not expected

hlolli22:12:33

if you have a css file in resources/public/css/stylesheet_from_luminus.css then its not surprising you get the css added.

roelofw22:12:29

Thanks, the slash did the trick and I have to change something in the body tag

roelofw22:12:17

time to sleep , have all a good night or day

fragamus23:12:49

hey how do I join #untangled