Fork me on GitHub
#clojure
<
2018-09-11
>
xiongtx00:09:57

Should this still be throwing an EOF exception?

(require '[clojure.edn :as edn])
(edn/read-string {:eof nil} "{:a")
;; => RuntimeException EOF while reading
Shouldn't it return nil instead?

hiredman00:09:14

I am not sure :eof nil has any effect for read-string

hiredman00:09:41

:eof is a read option that tells read what to return if the stream it is reading forms from is empty

hiredman00:09:17

so maybe the thing for read-string would be {:eof nil} with "" as the input

hiredman00:09:33

but if eof is encountered in the middle of reading a form that is always an error

xiongtx00:09:16

The docs could be more clear on that

borkdude08:09:26

lesson: be careful when you use multi-arity in combination with varargs?

martinklepsch10:09:16

I have two lists, with items list A ["a" "b" "c"] list B ["a" "b" "f" "z"] now I want to remove the items from the beginning of list B that are equal, ending up with ["f" "z"]. Previously I did something with (->> (map vector A B) (drop-while #(= (first %) (second %))) but that isn't working when the lists aren't of equal length. I could pad them but that just seems off. What's a nice way of doing this?

martinklepsch10:09:34

(def A ["a" "b" "c"])
(def B ["a" "b" "f" "z"])

mgrbyte10:09:53

is it important to preserve order?

mgrbyte10:09:01

A way that produces the result you want: (->> [B A] (map (partial apply sorted-set)) (apply clojure.set/difference) vec)

mgrbyte10:09:00

note only works if initial sequence of seqs if sorted by longest-length first. not sure it's "nice" really.

sgerguri10:09:53

(reduce #(drop-while (partial = %2) %1) B A)

sgerguri10:09:15

The idea in my solution is to essentially filter element by element using items from A, but there is no extra cost because drop-while will stop once the predicate returns false. Which means that once you've exhausted your "prefix" you will simply walk the rest of your filtering list (A in this case) but never traverse B anymore.

martinklepsch10:09:36

thanks! that reduce thing is neat. the set approach seems a bit more indirect but it also works, so yeah!

martinklepsch10:09:50

Thanks ❤️ (sorry for not crediting, should have done so but only realized after pushing and now I don't want to mess with history)

sgerguri10:09:50

"Lift" away! 🙂

enforser11:09:16

I tried to make a solution with loop! It prevents you from having to iterate over all of A. Compares the first two elements of A and B... if they are equal then recurse with the rest's of the lists, and if they are different then return B.

(loop [a '("a" "b" "c" "d")
       b '("a" "b" "f" "g" "h")]
  (if (and (= (first b) (first a))
           (not-empty b))
    (recur (rest a) (rest b))
    b))

miikka11:09:26

@martinklepsch

user=> (relativize-path "a/b.html" "a/a/b.html")
""

martinklepsch11:09:27

@U1NDXLDUG ugh, unlikely case but I see your point. Want to make a PR with a fix? 😄

miikka11:09:51

not really

sgerguri12:09:27

There's an early-termination version of reduce available as well:

(reduce
  #(let [new (drop-while (partial = %2) %1)
            same? (= %1 new)]
       (if same?
          (reduced new)
          new))
  B A)
Though honestly one should factor in readability, and unless you know your input is going to be huge I'd say early termination is not worth the effort.

gv12:09:30

hello, lein licenses - has an authentication problem accessing dependency poms. despite that lein deps is able to download the deps. Do you have an idea what lein licenses does wrong or what is needed to apply the :auth specification from profiles.clj in a plugin?

martinklepsch12:09:22

@gv it might be that it's simply not using any Auth stuff from project.clj and assumes all dependencies' POMs can just be retrieved without authentication (but I don't know/haven't checked)

slipset12:09:05

sorry if this is a faq, but has anyway a handy (macro) implementation of the js spread (…) operator.

gleisonsilva12:09:19

hello! may you can help me? it is possible to set, through repl, the *command-line-args* to be abble to try tools.cli options in place?

martinklepsch12:09:14

@U2CVD69EC take a look at binding

martinklepsch13:09:40

welcome! btw, I'd expect that tools.cli also has some APIs where you can just pass the data. Maybe try looking at it's tests or so...

slipset12:09:29

I understand that it’s mainly achieved by using apply, but…

taylor16:09:17

yeah I think you just want to use apply, do you really need it to be a macro? spread is a private implementation function

gv13:09:47

@martinklepsch yeah, the :auth data seems to get lost in the call chain

gv13:09:40

@martinklepsch it seems aether expects the auth data in the repository settings map - do you know where leiningen combines that?

gv13:09:59

it is hidden in classpath/add-rep-auth

ralf17:09:13

Has anyone ever written a plugin for Jenkins in Clojure?

hiredman17:09:46

like, a million years ago, I wrote a thing that let me embed a clojure repl in a jenkins process

danny21:09:28

do idependent/custom hierarchies get much use? anywhere i could be looking for reference?

danny22:09:44

oh this is very interesting, thanks!

quoll21:09:53

Maybe this should be in #off-topic, but it’s language related, so I’ll speculate out loud here… I wonder why Clojure doesn’t have clojure.core/ex-message as a complement to cljs.core/ex-message? Both Clojure and ClojureScript create an ExceptionInfo object with ex-info, and both retrieve the associated data structure with ex-data. Then in ClojureScript I can get the message with ex-message, but in Clojure I need to use interop to get the message. There’s no requirement that the core library for both languages be as close as possible to copies of each other, but it does seem inconsistent. It’s also strange to require host interop to get the message out of a native part of the language. Does anyone know if there is a good reason why this is missing please?

Alex Miller (Clojure team)22:09:49

cljs added it and no one ever filed a ticket to do so in CLJ

mfikes22:09:52

@quoll I was thinking of the same, but for ex-cause. Perhaps the answer is that Exceptions have messages and causes

Alex Miller (Clojure team)22:09:18

I’ll see if I can get that bumped for 1.10

mfikes22:09:21

Yeah, that one predates reader conditionals 🙂

Alex Miller (Clojure team)22:09:37

if anyone wants to check and update the patch, that would be helpful

andy.fingerhut22:09:03

You think it needs test cases? The implementations are fairly straightforward, so maybe no.

Alex Miller (Clojure team)00:09:51

I suspect there are some already

Alex Miller (Clojure team)00:09:58

but might need something new

vemv23:09:07

is there a plugin that will list the failing namespaces here at the bottom? as a summary

vemv23:09:34

else I have to scroll a lot and search them in the middle of huge stacktraces