Fork me on GitHub
#beginners
<
2017-08-04
>
bschrag00:08:16

This was working two weeks ago, breaks today when I launch CIDER from within the project.

error in process sentinel: Could not start nREPL server: Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in central ()

Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in clojars ()

This could be due to a typo in :dependencies or network issues.

If you are behind a proxy, try setting the ’http_proxy’ environment variable.

Per , there has been no change in version number. No change to my files, either. And no network issues here. But when I look at those URLs, I don't find anything looking like the specified artifacts. Any ideas how to proceed?

gdeer8103:08:09

@seancorfield @noisesmith thanks for all the help. I've learned a lot, but with the super-optimized version it's still taking over a minute with 100003 and my goal was under 12 seconds with 1000003

gdeer8103:08:14

I think I'm going to have to get creative with the for loop bindings

noisesmith04:08:02

curious, what would you do in the for bindings to optimize? (btw for is not a loop, it's a lazy sequence comprehension)

gdeer8104:08:07

@noisesmith sorry too many years of java, my keyboard autocompletes for to for loop lol

noisesmith04:08:33

just as long as we all understand the difference 😄

gdeer8104:08:26

okay so I can use a let binding in the for comprehension, so I need to derive the j value so I don't have to create two giant lists of numbers

noisesmith04:08:49

but for doesn't create two giant lists of numbers

noisesmith04:08:59

range is lazy, and nothing holds the head of those ranges

noisesmith04:08:26

only one element at a time has gc root for each sequence feeding the two bindings

noisesmith04:08:25

(well that's a simplification, it could be that chunk-size items at a time exist - something around 32 - I forget - but not your total input)

gdeer8105:08:53

I'm going to think about this some more while I do the dishes

gdeer8105:08:42

benchmarking this stuff is tricky; I might have to run this through sayid. but for now I'll sleep on it. posturepedic driven development

noisesmith05:08:41

visualvm or yourkit would verify where the remaining bottlenecks are in the code

jlmr07:08:11

Hi everyone, when trying to do this (apply case job-type jobs), I get "Can't take value of a macro". I think I understand why it can't, but can't figure out a solution. Any suggestions?

rauh07:08:04

@jlmr Yeah you can't do that with a macro. You can use the some function though to iterate over your jobs

jlmr08:08:47

Thanks, still fiddling with it, but looks like the way to go!

noisesmith13:08:12

case can be replaced with a hash-map lookup where the value in the map is a function you call

dadair18:08:07

First time writing macros, I'm trying to iterator over an argument list and basically get a map of {(keyword arg) ~arg} (so {:ref "value-of-ref"} if arg is ref). I have:

(defmacro defaction [spec fields]
  `(defn ~(symbol (str "make-" (name spec))) ~fields
     (s/conform ~spec (apply merge {:type (->SCREAMING_SNAKE_CASE (name ~spec))}
                             (for [f fields]
                               {(keyword f) ~f})))))
but I get CompilerException java.lang.RuntimeException: Unable to resolve symbol: f in this context, can anyone point out what I'm doing incorrectly?

bfabry18:08:55

@dadair ` is a syntax quote, so it will want to resolve any symbols inside of it

bfabry18:08:27

in this case you have f and fields which are both unresolvable

noisesmith18:08:43

also, the logic of that macro won’t work unless fields is a literal

noisesmith18:08:04

(you might already realize this)

dadair18:08:38

I'm basically trying to have a generic way of generating constructor functions off of a spec and a list of keys

bfabry18:08:12

I think you probably want f# and ~fields, but I haven't looked that closely

dadair18:08:13

so (defaction ::some-spec [ref value]) will become (defn make-some-spec [ref value] ..build map...)

bfabry18:08:07

no you want a in front of (apply, and you want to remove the from in front of spec and f

dadair18:08:10

perfect that worked

dadair18:08:35

Final form:

(defmacro defaction [spec fields]
  `(defn ~(symbol (str "make-" (name spec))) ~fields
     (s/conform ~spec ~(apply merge {:type (->SCREAMING_SNAKE_CASE (name spec))}
                              (for [f fields]
                                {(keyword f) f})))))

bfabry18:08:45

no worries

gdeer8120:08:57

@noisesmith @seancorfield my solution came down to simple algebra again 🤓

gdeer8120:08:46

remember I wanted to find number pairs only using one list so I was wondering if there was a way to calculate a valid corresponding j for every i

noisesmith20:08:12

oh of course there’s a math answer to that

gdeer8120:08:19

but then when I was doing the dishes I thought "maybe I don't need to test every pair" so I tried to come up with a number j for every i that was a potential solution for the problem

gdeer8120:08:16

I wracked my brain and then decided to just sleep on it and this morning it hit me that I just need to write out an equation and isolate the number I'm looking for

gdeer8120:08:14

we're looking for pairs i,j where (* i j) = sum (+ i j)

gdeer8120:08:26

so i ended up with j = (sum - i) / i

gdeer8120:08:32

but the results seemed to be off a little so I just added 1 to the denominator and ended up with j = (sum - i)/ i + 1

gdeer8120:08:17

then I printed out all the pairs using 26 as the upper bound because I know which pairs are right for that number

gdeer8120:08:31

so once again I saw the obvious answer in front of me; if i15 = j21 then i21 would equal j15 but once again to be able to do that kind of simple observation you would have to hold on to the entire collection

gdeer8120:08:59

so back to the math books again

gdeer8120:08:07

and the repl

gdeer8120:08:46

One obvious thing was that if the j ended up being a ratio it was immediately out

gdeer8120:08:27

then there were some j values that were larger than the upper bound of the collection so they were out

gdeer8120:08:22

and i and j should never be the same value so those were always out

gdeer8120:08:23

After I filtered all of the j values like that out the only thing left was a good value for j

noisesmith21:08:03

there’s room for some easy optimizations there btw

noisesmith21:08:57

(vec (remove nil? (map f coll))) will perform better as (into [] (comp (map f) (remove nil?)) coll)

noisesmith21:08:42

also, what is (long j) intended to do? I think you can just use j there

gdeer8121:08:54

oh wow, you're right, my version processed the value 1,000,003 in 932 msecs and your suggestions got it down to 261 msecs

noisesmith21:08:53

yeah - that’s the thing I love about transducers is the rewrite is usually trivial (it could be done by an editor macro) and the improvement is often quite substantial

noisesmith21:08:37

you could also try replacing (comp (map f) (remove nil?)) with (keep f) now that I think of it

gdeer8121:08:46

oh whoops, I didn't see that you turned it into a transducer, all I did was change vec to into []

gdeer8121:08:56

let me try the transuctional version

noisesmith21:08:05

that should also make a speed improvement

gdeer8121:08:39

the transducer version got it to 251 msecs

noisesmith21:08:58

with keep or map/remove ?

gdeer8121:08:43

oh with map/remove, let me try it with keep

gdeer8121:08:53

nice, we have a winner

gdeer8121:08:00

0.58 msecs

gdeer8121:08:53

This is amazing, a function that used to heat up my laptop, eat up all my RAM and cpu when it got a value over 50,000 now returns in nanoseconds on values over a million

noisesmith21:08:01

also the code hasn’t become harder to read

noisesmith21:08:55

on the contrary, imho

bschrag23:08:37

Trying to port to Clojure the Java API demo for the Netica Bayesian inference engine---knowing about Java only what I've read in Clojure for the Brave... So far, I have dealt with two Java import statements by including like content in an :import clause in core.clj's ns form and a :java-source-paths clause in the defproject (full clauses appended). CIDER loads all this without complaining. But, attempting to translate this line... Node.setConstructorClass ("norsys.neticaEx.aliases.Node"); ...as... (Node/setConstructorClass "norsys.neticaEx.aliases.Node") ...and entering at the REPL, I get this error: CompilerException java.lang.RuntimeException: No such namespace: Node, compiling:(*cider-repl edit-server*:43:19). JAR file at the above-specified path includes norsys/netica/Node.class. Any ideas what's wrong here? Hoping I can send a successful port back to Norsys. Full clauses:

:java-source-paths ["c:/NeticaJ_Win/NeticaJ_504/bin"] ; Abolute path ok?  Example: src/main/java

...

  (:import [norsys.netica.*]
           [norsys.neticaEx.aliases.Node])

noisesmith23:08:44

@bschrag .* doesn’t work

bschrag23:08:42

So, call out every class explicitly?

bschrag23:08:17

Ok, will try.

bschrag23:08:17

Trying something maybe simpler: Added [norsys.netica.Environ] (also in JAR) to :import, entered (Environ. null) at REPL. Got... CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: Environ, compiling:(*cider-repl edit-server*:43:19)

noisesmith23:08:40

odd that it didn’t complain about null

noisesmith23:08:20

did you reload the code after adding the import? either the import should have failed or calling the constructor should have gotten a different error (or worked)

bschrag23:08:46

Java code is new Environ (null);.

bschrag23:08:09

Yes, reloaded.

noisesmith23:08:17

OK, then (Environ. nil) should work, also you can use the classes without import in the repl

noisesmith23:08:48

invoking (narsys.netica.Environ. nil) is ugly, but it can make sense while experimenting at the prompt

bschrag23:08:54

edit-server.core> (norsys.netica.Environ. nil)
CompilerException java.lang.ClassNotFoundException: norsys.netica.Environ, compiling:(*cider-repl edit-server*:45:19) 

bschrag23:08:03

Maybe the path bit is not effective?

noisesmith23:08:14

have you restarted the repl since adding the narsys dep to your project?

noisesmith23:08:29

either that or it’s a typo in the name somewhere

bschrag23:08:01

Cut-and-pasted from Norsys' java demo.

noisesmith23:08:18

also you can just refer to a class to verify it exists

bschrag23:08:45

Restarting CIDER after each edit to defproject or ns. CIDER refresh breaks.

noisesmith23:08:00

=> java.util.Map
java.util.Map
=> this.does.not.Exist

CompilerException java.lang.ClassNotFoundException: this.does.not.Exist, compiling:(/private/var/folders/xb/gyyjxv511q7d9lr24s9_1rzc0000gr/T/form-init6129334502306779478.clj:1:1344)

bschrag23:08:29

Yes, I see.