Fork me on GitHub
#clojure
<
2021-06-03
>
Rob Haisfield00:06:09

Can someone please explain to me what Shaun Lebron might have been thinking about with this?

Alex Miller (Clojure team)02:06:35

(grey ... (white) ...
  (green ... (lt-green (gold) ...) 
    (blue)))

šŸ‘ 5
Rob Haisfield03:06:35

I guess my question is more about why he thinks the depth view is more meaningful than the nesting view

Alex Miller (Clojure team)03:06:16

I think it's only when the open expression is on the left, that you indent?

Alex Miller (Clojure team)03:06:48

and you don't with the ones in the middle? or maybe that's obvious, not sure

tlonist06:06:39

Iā€™m using test-runner (https://github.com/cognitect-labs/test-runner) for testing and made a github action for it, but it somehow constantly fails with

Syntax error (FileNotFoundException) compiling at (farmmorning/case_format_test.clj:1:1).
Could not locate farmmorning/util/case_format__init.class, farmmorning/util/case_format.clj or farmmorning/util/case_format.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
I double checked the file names, but couldnā€™t find any clues. can someone give me some advice?

tlonist06:06:07

here is the deps configuration.

:aliases {:dev     {:extra-paths ["dev/src"]}
           :test    {:extra-paths ["test"]
                     :extra-deps {io.github.cognitect-labs/test-runner
                                  {:git/url ""
                                   :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
                     :exec-fn cognitect.test-runner.api/test}}

borkdude07:06:35

Could be a .gitlibs problem. Try rm -rf ~/.gitlibs

borkdude07:06:42

and rm -rf .cpcache

dharrigan07:06:06

Also, would you be possible to share where the github action is?

tlonist07:06:38

yep. here it is.

name: test

on:
  - pull_request

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v2

      - uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'

      - uses: DeLaGuardo/[email protected]
        with:
          cli: '1.10.1.693'

      - name: Cache maven
        uses: actions/cache@v2
        env:
          cache-name: cache-maven
        with:
          path: ~/.m2
          key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/deps.edn') }}
          restore-keys: |
            ${{ runner.os }}-${{ env.cache-name }}-

      - name: Copy file
        run: cp -r resources dev/resources

      - name: Print paths
        run: clojure -Spath -X:test

      - name: Run test
        run: clojure -X:test

tlonist07:06:29

@U04V15CAJ those commands should be run from github action, right?

dharrigan07:06:40

I assume, the same command, clojure -X:test from your local system works flawlessly?

dharrigan07:06:47

you're able to run tests locally?

tlonist07:06:29

yes, they can be run locally without problem.

tlonist07:06:00

it fails only on github action.

dharrigan07:06:24

Hmm, I don't have much experience with github actions, so I'm afraid I can't offer more help šŸ˜ž

šŸ™ 3
Grigory Shepelev07:06:38

seems like malli channel is kinda dead. asking for help

ikitommi07:06:51

dead like in no-one answering in 20min? :thinking_face:

p-himik08:06:27

Please wait for at least a few hours before judging a channel as "dead" and reposting a question in a different one.

anonimitoraf09:06:27

By that definition, #clojure seems to be more dead

Stefan10:06:29

Hi all, I ran across Alex Millerā€™s article ā€œImproving Development Startup Timeā€ (https://clojure.org/guides/dev_startup_time). That seems like something I would want šŸ™‚ Iā€™m having trouble getting it to work however. When I execute (compile ā€¦) I only see the class files of that namespace, not the ones required by it. Whereas the article says ā€œtransitiveā€ which I take to mean that all namespaces it depends on should also be compiled. So I compile a few of them by hand, do a jack-in, and start my dev server, and it isnā€™t one bit faster. Now that may of course be due to other reasons, I didnā€™t profile the startup process, but Iā€™d like to make sure that Iā€™m not missing something. I added ā€œdevā€ and ā€œclassesā€ to extra-paths in deps.edn, I even added :jvm-opts ["-Dclojure.compile.path=classes"]. Any idea if Iā€™m doing something wrong?

borkdude10:06:58

> When I executeĀ (compile ā€¦)Ā IĀ onlyĀ see the class files of that namespace, not the ones required by it That's not what I'm seeing when I compile the top level ns of an ns tree

borkdude10:06:50

@stefan.van.den.oord

borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka (master) $ mkdir classes
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka (master) $ ls classes
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka (master) $ clj
Clojure 1.11.0-alpha1
user=> (compile 'babashka.main)
babashka.main
user=>
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka (master) $ ls classes
babashka    bencode     borkdude    cheshire    clj_yaml    clojure     cognitect   edamame     flatland    hf          hiccup      org         rewrite_clj sci         selmer

Stefan10:06:01

Strange. Thanks for checking!

caumond10:06:30

Hi, I find a performance gap between the rand-int clojure function and the java native one for instance .nextIn of java.util.Random. The gap is small for small amount of iterations but increasing with the number of iterations. @alexmiller,I saw some of your posts asking for feedback on performance, so I ask if I did something wrong, or if youo think this is something which should be improved in the clojure standard library, or maybe my case is so specific that I have to use interop?

(ns poc.defrecord.slack)

(def ^java.util.Random seed (java.util.Random.))
(defn compare-rands [nb-iter]
  [{:method :java-call
    :iterations nb-iter
    :time (with-out-str  (time
                          (dotimes [_ nb-iter]
                            (.nextInt seed 100))))}
   {:method :native-rand
    :iterations nb-iter
    :time (with-out-str (time (dotimes [_ nb-iter]
                                (rand-int 100))))}])

(compare-rands 2000000)
;; => [{:method :java-call,
;;      :iterations 2000000,
;;      :time "\"Elapsed time: 35.315238 msecs\"\n"}
;;     {:method :native-rand,
;;      :iterations 2000000,
;;      :time "\"Elapsed time: 127.318862 msecs\"\n"}]
;; => [{:method :java-call,
;;      :iterations 200,
;;      :time "\"Elapsed time: 0.017836 msecs\"\n"}
;;     {:method :native-rand,
;;      :iterations 200,
;;      :time "\"Elapsed time: 0.025678 msecs\"\n"}]

caumond10:06:23

In my original code there are two call to rand-intwhich seems to increase the influence:

(ns poc.defrecord.slack)

(def ^java.util.Random seed (java.util.Random.))
(defn compare-rands [nb-iter]
  [{:method :java-call
    :iterations nb-iter
    :time (with-out-str  (time
                          (dotimes [_ nb-iter]
                            (.nextInt seed 100)
                            (.nextInt seed 100)
                            (.nextInt seed 100))))}
   {:method :native-rand
    :iterations nb-iter
    :time (with-out-str (time (dotimes [_ nb-iter]
                                (rand-int 100)
                                (rand-int 100)
                                (rand-int 100))))}])

(compare-rands 200)
;; => [{:method :java-call,
;;      :iterations 200,
;;      :time "\"Elapsed time: 0.011242 msecs\"\n"}
;;     {:method :native-rand,
;;      :iterations 200,
;;      :time "\"Elapsed time: 0.039123 msecs\"\n"}]
;; => [{:method :java-call,
;;      :iterations 2000000,
;;      :time "\"Elapsed time: 93.312348 msecs\"\n"}
;;     {:method :native-rand,
;;      :iterations 2000000,
;;      :time "\"Elapsed time: 372.539035 msecs\"\n"}]

chrisblom10:06:45

rand-int calls Random/nextDouble under the hood, and does some mutiplication and casting to get an int

chrisblom10:06:53

so some overhead is expected

chrisblom10:06:17

Using time for benchmarks is not very reliable btw

caumond10:06:04

Ok I will try criterium. It's true the time are not stable

caumond10:06:12

Concerning the implementation your remark is an explanation but it may be possible to do better ?

caumond10:06:51

I looked at the implementation it is quite straightforward

chrisblom10:06:51

implementing rand-int using Random.nextInt(int bound) might be faster

chrisblom10:06:54

skipping the overhead of conversion

caumond10:06:39

You mean the double to int conversion?

chrisblom10:06:09

also Random.nextDouble looks like it does (a little) more work than Random.nextInt

chrisblom10:06:26

but probably the overhead is not that large

caumond10:06:56

Yes random functions are based on natural integer series.

caumond10:06:49

So generating double is more time consuming

caumond10:06:25

I know the difference is small but in my case it is doing a difference

chrisblom10:06:44

if you a processing on multiple threads then using ThreadLocalRandom might also speed things up

caumond10:06:34

I am not currently but it is im my plan so I take the advice

chrisblom10:06:39

rand-int and rand use Math/random(), which uses a shared java.util.Random instance for all threads, which may cause contention

Niklas11:06:03

I'm trying out :replace-deps with juxt/pack.alpha.git like https://github.com/juxt/pack.alpha/pull/92/files, I consistently get a few seconds slower run-times, (I run once to warmup and then average over three runs). Is that expected?

Niklas11:06:40

this:

:pack {:extra-deps {pack/pack.alpha {:git/url ""
                                                :sha "042c61410b1851957ae5f77cfe26a255837172cc"}}
                  :main-opts ["-m"]}
is consistently faster than
:pack {:replace-deps {pack/pack.alpha {:git/url ""
                                                :sha "042c61410b1851957ae5f77cfe26a255837172cc"}}
                  :main-opts ["-m"]}

Niklas11:06:18

I thought it would be faster since it would load less code, but maybe I'm misunderstanding it?

Alex Miller (Clojure team)11:06:47

The first time you run it will compute and cache classpaths so make sure youā€™re accounting for that

Alex Miller (Clojure team)11:06:23

I would generally have the same expectation as you - replace should replace the project deps so include less

Alex Miller (Clojure team)11:06:53

You can use -Stree or -Spath to confirm that

Niklas11:06:50

when I benchmarked I ran once to "warmup" and averaging 3 runs.

Niklas11:06:00

I'll take alook at -Stree/-Spath

Niklas11:06:45

actually, after killing all other applications on my laptop the results look better

Alex Miller (Clojure team)14:06:58

once all that stuff is downloaded and cached, there should be no real difference here - in both cases you're just running the program

Niklas14:06:49

aha, so the main difference is when there is no cache?

Alex Miller (Clojure team)14:06:08

yeah, it's just a question of how many deps you have to download

Alex Miller (Clojure team)14:06:32

but once you download them to your .m2/.gitlibs ... that's all cached

ChillPillzKillzBillz15:06:14

What is a good place to look for templates for clj-new?

craftybones15:06:53

is there anyway to prevent a symbol from being unmapped via ns-unmap ?

Alex Miller (Clojure team)15:06:26

why do you want to do that?

craftybones15:06:09

I donā€™t. Someone asked me if it could and I was almost certain that it couldnā€™t but wanted to check anyway.

craftybones15:06:05

The person who asked me is worried about malicious code. Of course, this person hasnā€™t discovered eval yet šŸ˜„

Alex Miller (Clojure team)15:06:03

powerful tools are also often dangerous :)

craftybones15:06:37

Yes, of course. What is interesting is that truly dynamic systems have to allow for the change of their own environments/source, and everything from DNA to running code is susceptible to maliciousness

Ed15:06:20

the converse is also true. Only dynamic safety is real safety. For example, unchecked array bounds have been a massively costly impact of trusting static assumptions over dynamic reality ...

borkdude15:06:57

@srijayanth if you want to have a kind of sandbox that forbids certain vars, you could take a look at sci

user=> (sci/eval-string "(ns-unmap *ns* 'inc)" {:deny ['ns-unmap]})
Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:51).
ns-unmap is not allowed!

borkdude15:06:47

clojail is another approach which relies on java sandboxing

rickmoynihan16:06:34

How do a type hint a vararg call for an array of Foo objects? I know to call with (into-array Foo [])

rickmoynihan16:06:03

however I try it I seem to get a reflection warning šŸ˜•

rickmoynihan16:06:35

Iā€™ve tried variants of things like (a and b are already type hinted) (.method a b ^"baz.bar.Foo" (into-array Foo [])

seancorfield16:06:31

^"[Lbaz.bar.Foo;"

seancorfield16:06:10

See (type (into-array Foo [])) for the string representation of the type.

rickmoynihan16:06:10

ah sorry thatā€™s already what I haveā€¦ I misstyped it here

seancorfield16:06:48

Perhaps thereā€™s some other aspect of ambiguity in the call then?

seancorfield16:06:09

Does the reflection warning provide a bit more specific information?

rickmoynihan16:06:26

ok real code is:

(def default-context ^"[Lorg.eclipse.rdf4j.model.Resource;" (into-array Resource []))

(defn index-data! [input-files]
  (let [repo (repo/sail-repo (repo/memory-store))]
    (doseq [^File input input-files]
      (with-open [^RepositoryConnection conn (repo/->connection repo)]
        (let [^RDFFormat fmt (.orElse (Rio/getParserFormatForFileName (str input)) nil)]
          (.add conn input "" fmt default-context))))
    repo))
Reflection warning,
swirrl/qb_tools/concept_scheme/positions.clj:89:11 - call to method add on org.eclipse.rdf4j.repository.RepositoryConnection can't be resolved (argument types: java.io.File, java.lang.String, org.eclipse.rdf4j.rio.RDFFormat, unknown).

rickmoynihan16:06:35

hmm actually the docs are one minor version out, from what I have on my classpath :thinking_face:

seancorfield16:06:19

Maybe the type hint on the def has to be before the symbol instead of on the value?

rickmoynihan16:06:47

ahh thatā€™s it thanks

seancorfield16:06:08

dev=> (def example ^"[Ljava.lang.String;" (into-array String []))
#'dev/example
dev=> (meta example)
nil
dev=> 

rickmoynihan16:06:40

6pm code blindness setting in šŸ˜©

rickmoynihan16:06:45

hmm prints correctly

rickmoynihan16:06:00

maybe the issue is something else

chouser19:06:29

Is there anyone here who provides hands-on introductory Clojure workshops for corporate teams, or can recommend such from personal experience?

seancorfield19:06:15

Hadnā€™t Cognitect used to offer that? @alexmiller?

Ed20:06:43

I can't personally recommend him, but I like the output of Eric Normand and it sounds like he does that sort of thing: https://lispcast.com/training/

Alex Miller (Clojure team)20:06:47

you can ping <mailto:[email protected]|[email protected]> - we are entertaining such requests but I don't know the full status

chouser05:06:12

Thanks, all! I should have mentioned I'd found the community link, but wasn't sure how vetted or up to date it is.

Alex Miller (Clojure team)12:06:39

It is as up to date as most internet information :)