Fork me on GitHub
#beginners
<
2018-05-21
>
noisesmith01:05:05

@tkjone I think that's an instruction telling clojure.tools.namespace not to reload that namespace when changed https://github.com/clojure/tools.namespace#disabling-refresh-in-a-namespace

noisesmith01:05:55

nothing but tools.namespace should be looking for that metadata, so you shouldn't expect any other code's behavior to change based on it

xlevus12:05:56

I have a http-kit/compojure/compojure-api project that I'm building up bit by bit (and probably looking like a luminus app). Is there a way to get the reload ring middleware to trigger when non-route files change? At the moment I'm pumping (require 'project.my.ns :reload) into the REPL every time I change a file

xlevus13:05:43

oh, I see the middleware looks for changes in the 'src' directory.

athomasoriginal15:05:43

What would people say is conveying a clearer message of what the developer is trying to do:

(def last-item-index (dec data))

;; or

(def last-item-index (.indexOf data (last data)))

dpsutton16:05:52

the message is in the name and they are the same.

👍 4
noisesmith17:05:24

they behave differently if items repeat

athomasoriginal16:05:11

Cool, but then if we removed the name?

(dec total-items)

;; or

(.indexOf data (last data))

ghadi16:05:04

If the collection is a vector you can always call peek to grab the last item

ghadi16:05:18

last is a linear scan

ghadi16:05:44

I would definitely not use .indexOf

ghadi16:05:44

user=> (.indexOf [2 3 4 3] 3)
1

ghadi16:05:53

not what you'd expect @tkjone

dpsutton16:05:39

why not just (count data)

👍 4
troglotit16:05:28

I was skimming and couldn’t understand, but when read (count data) I was quite surprised

troglotit16:05:47

(dec a-vector) - throws exception for vector.

athomasoriginal18:05:30

Sorry, total-items would be a number and yes, the .indexOf solution is not my preference either, and as you mentioned, does not work in all cases. What I was trying to do is see if there was a clearer way of finding the last index in a vector of items. The first way was me counting the vector, and then decrementing it by 1 because I want to use the last index in a cljs node array to select the last item

noisesmith20:05:53

Decrementing the count not only works, but is efficient with vectors O(1) compared to O(n) finding the index of the last item. (if somehow you were forced to look up by value and not known position, isn't there a lastIndexOf also?)

athomasoriginal20:05:27

Good points. Thank you!

jimbob15:05:04

nice job with this! 😄

Vincent Cantin12:05:25

I am working on a serie of intense transducer exercises. Will publish on the 30th. Stay tuned.

Vincent Cantin23:05:53

Feedback is welcome.