Fork me on GitHub
#beginners
<
2018-09-12
>
stardiviner06:09:39

I need to debug an private function parse-loc failed which is defined in an library kce-clj. When I invoke it in Emacs CIDER, it always has another middleware issue caused an exception. So I have to debug function in plain lein repl, I'm running code:

(with-open [f ( "/home/stardiviner/Documents/learning/Clojure/kindle-export-notes/My Clippings.txt")]
    (kce-clj/extract f "UTC"))
which kce-clj/extract invokes parse-loc internally. I got error:
NullPointerException   clojure.string/lower-case (string.clj:217)
I want to add println in parse-loc private function so that I can know which line of file caused this error. Does anyone have some way to do this?

andy.fingerhut08:09:37

Often you can print a full stack trace showing all of the stack frames, each with its own file name and line number. Try (clojure.repl/pst) Sometimes they can be fairly long and contain many lines you do not care about, but find the line that has clojure.string/lower-case (string.clj:217), probably near the beginning of the output (you may need to scroll back), and look at the next line or two for parse-loc.

Denis G09:09:44

Does anybody know what continuation means?

Denis G09:09:04

It is somehow related to trampoline thingy, but still don't quite get it

stardiviner10:09:40

@andy.fingerhut I got this output by (pst).

kindle-export-notes.core=> (pst)
NullPointerException
        clojure.string/lower-case (string.clj:217)
        clojure.string/lower-case (string.clj:213)
        kce-clj.core/parse-loc (core.clj:26)
        kce-clj.core/parse-loc (core.clj:23)
        kce-clj.core/parse-cat-loc (core.clj:34)
        kce-clj.core/parse-cat-loc (core.clj:30)
        kce-clj.core/parse-meta (core.clj:50)
        kce-clj.core/parse-meta (core.clj:47)
        kce-clj.core/parse-entry (core.clj:57)
        kce-clj.core/parse-entry (core.clj:53)
        kce-clj.core/lazy-extract/fn--201 (core.clj:66)
        clojure.core/map/fn--5587 (core.clj:2747)
nil

stardiviner10:09:50

This doesn't give out too much information.

stardiviner10:09:32

I found how, I redefined that privated function in the library namespace, and add println line before the function result. Then found which line of file caused this problem. Because some lines of file are Chinese, so parsed error.

danny16:09:13

i’m sure i’ve missed something, but does the manifold library provide an equivalent to core.async’s pipeline-async in the sense of “kick off a bunch of processes that and then collect their results as they complete”? its stream map and reduce seem to wait for each deferred value to resolve before continuing.

danny16:09:21

or maybe (likely) i’m thinking about this all wrong

danny16:09:37

the processes would be io-bound and blocking, say uploading files to s3 via amazonica

danny16:09:22

this toy seems to behave the way i’d like:

@(let [ns (a/to-chan (range 10))
       out (a/chan)]
   (a/pipeline-async
     4
     out
     (fn [n c]
       (a/go
         (a/>! c (a/<! (a/thread
                         (println "start " n)
                         (Thread/sleep (* 100 (rand)))
                         (println "finish " n)
                         n)))
         (a/close! c)))
     ns)
   (s/reduce conj [] (s/->source out)))

danny17:09:02

but then this other toy seems to go more or less one-at-a-time:

@(let [limit 10
       ns (range limit)]
   (->> ns
     (s/map (fn [n]
              (d/future (println "start " n)
                        (Thread/sleep (* 1000 (rand)))
                        (println "finish " n)
                        n)))
     (s/reduce conj [])))

borkdude17:09:52

@clarkenciel have you looked at zip ?

danny17:09:19

hmm i haven’t, i’ll check it out thanks!

danny17:09:57

okay now i have

@(let [limit 10
       ns (range limit)]
   (->> ns
     (s/map (fn [n]
              (d/future (println "start " n)
                        (Thread/sleep (* 1000 (rand)))
                        (println "finish " n)
                        n)))
     (s/stream->seq)
     (apply d/zip)))
and that seems to behave how i’d like!

danny17:09:24

i.e.

start  0
start  2
start  3
start  4
start  5
start  6
start  8
start  1
start  7
start  9
finish  7
finish  9
finish  0
finish  3
finish  8
finish  1
finish  5
finish  2
finish  6
finish  4
(0 1 2 3 4 5 6 7 8 9)

borkdude17:09:00

@clarkenciel right:

@(apply d/zip (map d/success-deferred (range 10)))
(0 1 2 3 4 5 6 7 8 9)

danny17:09:48

awesome thank you! i knew there had to be something like this

cristibalan17:09:43

Hi. I'm trying to add levand/heat {:git/url "" :sha "6f2dbba0c055b281e1624b5814fd84c27d64f7bb"} to my deps.edn and I'm getting Error building classpath. Manifest type not detected when finding deps for levand/heat in coordinate ... after the repo is cloned and checked out. Does this mean the included project is missing a deps.edn?

cristibalan18:09:23

Adding a deps.edn fixed it, but, for some reason, I also had to add a :deps/manifest :deps.

levand/heat {:git/url ""
                 :sha "6f2dbba0c055b281e1624b5814fd84c27d64f7bb"
                 :local/root "/path/to/heat"
                 :deps/manifest :deps}
{:paths ["src"]
 :deps
 {org.clojure/clojure {:mvn/version "1.9.0"},
  enlive {:mvn/version "1.2.0-SNAPSHOT"}}}

borkdude17:09:24

@cristibalan you might also want to try #tools-deps

👍 1
Mario C.17:09:28

lein cljsbuild once is stops showing warnings after a couple of times of running that command.

Mario C.17:09:36

I don't think its random

Mario C.17:09:55

Does this have anything to do with cacheing perhaps?

noisesmith17:09:59

are you cleaning in between?

noisesmith18:09:18

yes, I would assume if a cached artifact is used, you wouldn't get the warning

Mario C.18:09:38

I did run lein clean

Mario C.18:09:45

but the warnings still dont come up

noisesmith18:09:55

does lein know to clean the js artifacts cljsbuild makes?

noisesmith18:09:17

a common configuration issue is creating a custom target js dir and not adding it to clean-targets

noisesmith18:09:22

it's not automatic

Mario C.18:09:29

I don't know. How would I find out?

Mario C.18:09:44

It looks like we are creating a custom target js dir

noisesmith18:09:50

did you customize where compiled js goes in cljsbuild? if so you also need to customize clean-targets

noisesmith18:09:12

warning, that does mean lein will throw away everything in that directory when you clean

Mario C.18:09:52

Just to make sure we are on the same page. You are talking about :compiler {:output-to "path/to/site.js"}

noisesmith18:09:31

there's also output-dir iirc

Mario C.18:09:13

How would I customize clean-targets?

noisesmith18:09:30

lein help sample shows, but it's pretty intuitive

Mario C.18:09:07

let me give it a go

noisesmith18:09:49

looks like adding :output-to to :clean-targets vector even works

noisesmith18:09:16

err, [:cljs-build :compiler :output-to] or something like that

Mario C.18:09:52

would the vector work if :cljsbuild is set up like this :cljsbuild -> :builds [(which is a vector with a single map)] -> :compiler -> :output-to ?

noisesmith18:09:24

[:cljsbuild :builds :a-build-name :output-to]

noisesmith18:09:28

or maybe just hard-code the output-to value instead

Mario C.18:09:03

Got it! :thumbsup:

Mario C.18:09:19

My only gotcha is that it now doesn't delete the target directory lol

Mario C.18:09:22

But I can figure that out

JH18:09:52

Does anyone has recommendations for referencing environment variables from the project.clj?

JH18:09:39

Ah that might do it, thanks

noisesmith18:09:12

sometimes ~(System/getenv "FOO") inside the project.clj works - depends on how much you need

borkdude19:09:52

in boot that works for sure, but I don’t want to get into boot vs lein now 😉

noisesmith19:09:12

yes, the ~ makes sure it works with lein

noisesmith19:09:42

project.clj is in an implicit syntax-quote

hoynk19:09:40

Hi, I am in need of an introductory book for someone with little programming knowledge and none in functional programming. Do anyone have a good indication?

alexmiller19:09:17

maybe consider “How to Design Programs” by Felleisen + Findler?

👍 1
alexmiller19:09:07

depends a lot on your goals of course

hoynk19:09:37

It seams a book that would attend my needs, my only concern is it not being exactly clojure. I was thinking about SICP but afraid it would be too dense.

borkdude20:09:46

wasn’t there a clojure port of SICP? I don’t know how far it got

john20:09:48

I haven't read it since the first edition, but I thought "Programming Clojure" was gentle enough for beginners.