Fork me on GitHub
#clojure
<
2018-04-25
>
qqq01:04:59

how do I get the size/length/count of an object of type [B ? (byte array)

seancorfield01:04:35

@qqq count will work...

4
qqq03:04:01

@seancorfield :for some reason, I was trying (.count ...) instead of (count ...)

seancorfield04:04:02

Overthinking/over-complicating things? 🙂

seancorfield04:04:19

One of the things that still charms me, almost daily, working with Clojure, is that so often the very simplest thing I can imagine is what works!

☝️ 4
qqq05:04:51

I have done Clojure + Cuda via ClojureCuda. I have done Clojure + OpenGL via JOGL. However, I don't know how to mix the two. Does anyone have sample Clojure glue where the Cuda code writes to a VBO, which the JOGL code then picks up for rendering? I suspect this is possible, but just have not done this yet.

dnaeon08:04:55

Is there a pretty-print version of pr-str ? I have a data map which I need to pr-str, but would like to keep that pretty formatted.

sundarj08:04:19

@dnaeon you can use with-out-str with pprint

dnaeon08:04:12

@sundarj the thing is that some of keys in the map are Records, so when I do with-out-str with pprint I lose the tags for those records, so later on I cannot read them back.

sundarj08:04:10

i see. at a guess, you would have to muck about with pprint's configuration to change that

Alex Miller (Clojure team)11:04:29

You can extend the print multimethods to support record instances

kah0ona11:04:07

If I have a legacy java jar, not on maven or whatever, and I want to use it in my clojure project (leiningen for building), what is the best way to use it?

kah0ona11:04:29

i read somewhere it should be in the lib/ dir in my project, is that all that’s needed?

Russ Olsen13:04:02

@kah0ona I generally just upload the jar to my local maven repo and then treat it like any other jar: https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project

kah0ona13:04:21

ah ok thanks

kah0ona13:04:28

yeah I’ll try that

tankthinks13:04:13

Is there any practical (performance maybe?) difference between: (->> data (mapcat transform-fn) (into []) ;; which will expand to (into [] (mapcat transform-fn data)) and (into [] (mapcat transform-fn) data)

tankthinks13:04:41

or is this just a visual preference thing

tankthinks13:04:15

(insert obvious missing ) after (into []))

moxaj13:04:49

@tankthinks the second one is faster as it does not materialize the intermediate collections (https://clojure.org/reference/transducers is a good read)

tankthinks13:04:10

that’s what I thought … yup … should have checked the docs 😃

zarkone14:04:50

Hi! Have a question about reader conditionals: I want something like :nodejs to separate browser and nodejs environment. However, I can't find a way how to extend reader conditionals features set. I've tried to use something like (= :nodejs (get-in @cljs.env/*compiler* [:options :target])), but it is doesn't work in cases like :require in ns macro, for example. Is it possible to extend this feature set? any links on how to do that? thanks!

Alex Miller (Clojure team)14:04:47

reader conditional features are not currently extensible

zarkone14:04:11

I see.. Thanks! Any plans on making it extensible? does it make sense at all? 🙂

Alex Miller (Clojure team)14:04:21

The original design was extensible and in fact the reader implementations actually do support extensible features. However, in the end we decided to reduce scope and make the “platform” features hard-coded for the purposes of reading source code. (You can activate custom features through the reader api when you are controlling the read.)

Alex Miller (Clojure team)14:04:13

The problem with custom features is that you are then potentially inviting an explosion of code “variants” and we would like to exert as much negative pressure on that as possible.

💯 4
Alex Miller (Clojure team)14:04:27

We may revisit this in the future but no plans to change it in the short term.

andrea.crotti14:04:06

Suppose I have a vector like (def myl [[[1]] [[2] [3]]]) Is there a way to partially flatten it and get [[1] [2] [3]] ?

andrea.crotti14:04:20

flatten does actually too much

andrea.crotti14:04:40

ah dammit apply concat might work

mkvlr14:04:55

@zarkone I believe @thheller allows you do what you want in shadow-cljs

ghadi14:04:11

one of my favorite things is the transducer variant of mapcat is defined as stacking two transducers (comp (map f) cat)

😄 4
zarkone14:04:12

@mkvlr thanks, will check this out now!

zarkone14:04:51

@ghadi yes, looks elegant 🙂

zarkone14:04:36

@mkvlr exactly what I was looking for, thank you!

👍 4
naomijub16:04:22

What do you think of Clojure with rust as its target?

naomijub16:04:47

specially after oracle's uncertainties

orestis16:04:22

Rust is a too low-level target for Clojure, AFAICT.

naomijub16:04:46

for some time there was a Clojure on C

dominicm16:04:24

isn't garbage collection the big gotcha here (quoting tbaldridge)

mikeb16:04:40

Yeah, pretty sure GC will be the issue with rust. Coincidently I've been wondering about a clojure that targets golang, which has a pretty stellar GC and none of the oracle issues.

orestis16:04:01

I asked recently on the off-topic channel but go no response — ClojureScript paved the way somewhat to have Clojure-on-Clojure, so I’m wondering if adding another runtime could now be easier?

gklijs17:04:34

GC and Jit must be handled, bit that's also true for must other non-jvm targets. I also see rust as a way to easy write c, so I don't get to closure to rust that well. Clojure to c would be nice, but has the same challenge for the GC.

shaun-mahood17:04:35

@U26FJ5FDM: There's a dialect for Clojure on C++ that looks pretty interesting - https://ferret-lang.org/

gklijs17:04:43

Those wrappers look a lot more scary to me than Java interop, https://git.nakkaya.com/nakkaya/ferret-teensy-flight-sim/blob/master/core.clj#L12 and I have no c or c++ experience. One of the things I really like a about clojure is that you can use all the Java and clojure libraries. It would take a lot of work to get the same kind of thing without using the JVM. But it might also let things run faster and/or with less memory.

gtrak17:04:53

what are oracles uncertainties?

orestis17:04:20

There’s a lot of brouhaha online about the recent licensing and schedule changes. There were a couple of articles on proggit/HN that Oracle will start to charge for LTS releases, based on a big misunderstanding of OracleJDK/OpenJDK, AFAICT.

sgnl17:04:18

Oracale, The Vendor Formerly Known As Satan

👍 8
gtrak17:04:15

interesting, thx

qqq17:04:17

what is the fastest way to convert a n-elem byte-array to a n-elem float-array ? (each byte becomes a float valued 0 -> 255.0)

rnagpal18:04:30

I have a cljc file in lein project and I have cljc test for it in the test folder Now I want to include cljc test in both clj and cljs test runners and see the results of the tests to include and run cljc test in clj test runner, I have to compile it and :aot :all doesn’t seem to work in the test folder How do I compile the cljc file in test folder ?

hiredman18:04:30

what makes you say you have to aot?

rnagpal18:04:17

@hiredman basically it tries to find a .class file with the same name, so I tried :aot :all

hiredman18:04:13

what tries to find a .class file?

hiredman18:04:55

lein test certainly doesn't

rnagpal18:04:06

I have a clj test runner which has (t/run-all-tests [cljc-namespace])

hiredman18:04:52

so not lein test, and t must be clojure.test?

hiredman18:04:02

clojure.test definitely doesn't look for class files

rnagpal18:04:22

and I get Caused by: java.lang.ClassNotFoundException: cljc-namespace

hiredman18:04:44

because you aren't quoting the name

hiredman18:04:19

(t/run-all-tests '[cljc-namespace])

rnagpal18:04:30

Now I get Caused by: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.regex.Pattern

rnagpal18:04:46

i.e. with the quote

hiredman18:04:01

I think you meant to use a different function from run-all-tests

hiredman18:04:13

run-all-tests doesn't take a list of namespaces, it takes a regex

hiredman18:04:24

you likely meant to call run-tests

hiredman18:04:33

(which does take a list of namespaces)

hiredman18:04:09

clojure.test also doesn't load any namespaces, so you have to make sure the namespace is loaded before trying to run the tests in it

rnagpal18:04:32

I tried (t/run-tests ’cljc-namespace) and it complains Caused by: java.lang.Exception: No namespace: cljc-namespace found

rnagpal18:04:48

this is my test paths :test-paths ["test/clj" "test/cljs" "test/cljc" "test/doo"]

rnagpal18:04:04

and it includes cljc files

hiredman18:04:50

the paths don't matter, because as I said, clojure.test doesn't do any code loading

hiredman18:04:05

have you run (require 'cljc-namespace) ?

rnagpal18:04:58

I have

(ns test-runner
  (:require [clojure.test :as t :refer [is are deftest testing]]))

hiredman18:04:19

so you are not loading the cljc-namespace, so of course when you ask clojure.test to test it, it throws an error because the namespace you asked it to test doesn't exist (where exist here means exists in the clojure runtime, not exists like there is a file on disk that defines it)

hiredman18:04:07

you must load the definitions of tests first yourself before you can ask clojure.test to run the tests

hiredman19:04:46

I don't know the specifics of your situation, but it seems like you are a beginner, so some advice, don't use single segment namespaces like test-runner, instead use something like test.runner (the . is a segment separator). The reasoning for that is if you do aot compile a single segment namespace, you end up with a class in the default package which is usually considered kind of bad jvm citizenship

rnagpal19:04:16

Thanks @hiredman for the clarification. However my namespace are in the format of x.runner, just changed it to not share the exact name I did try (require ’cljs-namespace) and I now get Caused by: java.lang.IllegalAccessError: reader-error does not exist

rnagpal19:04:39

I have [org.clojure/tools.reader "1.2.1"] in my classpath

hiredman19:04:59

have you tried to load your source file previously

hiredman19:04:47

likely you have errors in it (syntax, using defs from other namespaces you haven't referred, etc)

hiredman19:04:26

you may also have a bunch of stale class files left over from when you were aot compiling, which can really trip you up

hiredman19:04:08

(I strongly recommend against aot compiling, the trade offs are just not worth it)

rnagpal19:04:58

Thanks @hiredman seems a problem in my cljc test file

rnagpal19:04:07

which is getting included

rnagpal19:04:27

as you mentioned I didn’t had a require

rnagpal19:04:37

now it loads the cljc test file

rnagpal19:04:44

and fails in one of the file

rnagpal20:04:12

@hiredman it works now

(ns x.runner
  (:require [clojure.test :as t :refer [is are deftest testing]]))
(t/run-all-tests #"xx\..*")

rnagpal20:04:50

the root cause was that I didn’t had “test/cljc” in my :test-paths

rnagpal20:04:10

thanks a lot for trying to help @hiredman