Fork me on GitHub
#clojure
<
2023-01-25
>
jaide06:01:14

Anyone recall a talk where Stuart Halloway defined a spec for a third-party library, then caught an obscure bug using generative testing on it?

seancorfield06:01:44

I think that's Running With Scissors: https://github.com/matthiasn/talk-transcripts/blob/master/Halloway_Stuart/RunningWithScissors.md where he found a bug in the chart library?

jaide07:01:50

Oh right it was a charting library! Yes this is the one, good memory 😁

motform10:01:02

Is there a way to programatically create aliased qualified keywords, ie, ::itunes/summary? I'm using clojure.data.xml and have defined an xmlns alias with (xml/alias-uri 'itunes ""). However, as far as I'm aware, there is no way to programatically create a :: keyword that can resolve to the alias created by xml/alias-uri. Is that correct?

motform10:01:56

I can kind of see it being a reader thing, how :: keys must be known in advance in order to be resolved, as opposed to the concrete qualified syntax that has no outside dependence.

delaguardo10:01:12

(ns-name (get (ns-aliases *ns*) 'itunes)) should give you qualified namespace symbol which alias refer to.

delaguardo10:01:25

user=> (require '[clojure.data.xml :as xml])
nil
user=> (xml/alias-uri 'xh "")
nil
user=> (def xh (name (ns-name (get (ns-aliases *ns*) 'xh))))
#'user/xh
user=> (keyword xh "summary")
:xmlns.http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml/summary

❤️ 2
motform10:01:54

Excellent, thank you very much!

borkdude12:01:58

It's a pity that :as-alias can't be used in this case in an obvious way

delaguardo13:01:43

i guess that means using URI instead of namespace in require with as-alias

Alex Miller (Clojure team)13:01:54

I don’t see how that would be possible while still getting the uri aliasing

Alex Miller (Clojure team)13:01:13

I guess it would mean evaling the alias name expression. I don’t think that’s a door we want to open

Ben Sless14:01:08

Is there a way to bind clojure.test/*load-tests* when starting a REPL?

jpmonettas16:01:00

you mean like this ?

clj -e "(do (require 'clojure.test) (alter-var-root #'clojure.test/*load-tests* (constantly true)))" -r

vemv15:01:30

That might be a reasonable var to add to https://github.com/clojure/clojure/blob/527b330045ef35b47a968d80ed3dc4999cfa2623/src/clj/clojure/main.clj#L83-L101 so that you can just set! it Worth an ask :)

vemv15:01:01

Personally I use clojure.test/*load-tests* in conjunction with a specific way of using tools.namespace

Ben Sless15:01:28

A jvm property is also good 🙃

marrs17:01:36

Are there any strategies for gathering the modules belonging to a namespace at runtime. So if I have my.ns.foo and my.ns.bar, can I do something like (map (fn [x] (x/method args) (gather-modules-under 'my.ns))? such that I get the equivalent of (do (my.ns.foo/method args) (my.ns.bar/method args))

hiredman17:01:07

namespaces don't exist in a hierarchy like that

hiredman17:01:48

there is no relationship between my.ns.foo and my.ns.bar other than the name shares a common prefix

hiredman17:01:15

and in clojure there is nothing called a "module"

marrs17:01:33

sub-namespace then, but you've answered the question. So I guess my other option is to use in-ns to separate "modules" into multiple files and then use something like ns-publics to access their vars. I seem to remember having problems with that strategy previously when it came to hotloading changes to the namespace

marrs17:01:56

Thanks for setting me straight on the namespaces.

hiredman17:01:00

"sub-namespace" implies some kind of hierarchy between namespaces still, and there is none. it is a flat key space (a single k/v map not a filesystem of nested trees)

marrs17:01:31

I got that, thanks. I was just clarifying what I meant by "module"

gleisonsilva18:01:44

Hello! May you can point me out some solution... I do need to generate some Parquet files from my Clojure code... but I'm struggling to find a way... all examples that I've found are broken in some way... I've found this PigPen library from Netflix, but even the example shown in the readme of the project are not working... Can someone help me?

gleisonsilva19:01:00

Hi! I'm trying to write this snippet of Java code into Clojure, but not succeed... can you help me?

Schema schema = new Schema.Parser().parse(avroSchema)

hiredman19:01:17

Schema$Parser is the name of the class

lukasz19:01:27

and you need to import it explicitly

hiredman19:01:19

Parser is a nested class in Schema in java, and the way that gets compiled for the jvm is Parser generates a class named Schema$Parser entirely distinct from the Schema class

gleisonsilva19:01:38

This way?

(:import
   [org.apache.avro Schema$Parser] )

👍 4
lukasz19:01:57

you need both Schema and Schema$Parser

p-himik19:01:01

Ah, I thought you meant for just that line. Right.

gleisonsilva19:01:49

it works! tks, guys! Can I ask another thing? How can I rewrite this piece of code?

ParquetWriter<GenericRecord> writer = 
  AvroParquetWriter.<GenericRecord>builder(path)
                   .withSchema(schema)
                   .withCompressionCodec(CompressionCodecName.SNAPPY)
                   .build()

gleisonsilva19:01:48

this 'Generics' thing... I've no idea how to code this with clojure..

p-himik19:01:47

Write the code as if the <...> parts don't exist.

gleisonsilva19:01:00

I've trid this way, but do not work:

writer (-> (.builder AvroParquetWriter path)
         (.withSchema schema)
         (.withCompressionCode CompressionCodecName/SNAPPY)
         (.build))

gleisonsilva19:01:25

I got this error: "No matching method builder found taking 1 args for class java.lang.Class"

p-himik19:01:40

Because builder is static, it should be (-> (AvroParquetWriter/builder path) ...).

😀 2
gleisonsilva19:01:02

thank you very much!

👍 2
jumar06:01:50

Btw. there's #C053AK3F9 channel which would be better fit for these questions

gleisonsilva19:01:14

I've tried this way

(let [schema (.parse (Schema.Parser.) avroSchema)])
but don't work...

jdkealy21:01:55

Is there a way to invoke a long-running function in the REPL that will continue even if the REPL process dies ?

hiredman21:01:31

(long answer, depends what you mean by process, but if you mean a os process, then the only way to run something that outlives a given process is to run another process)

jdkealy21:01:05

So i thought a future would do it

jdkealy21:01:12

(future (do-long-running-thing))

hiredman21:01:16

a future is another thread

jdkealy21:01:16

but i can't tell if it is

jdkealy21:01:39

so i lost the connection to the REPL and it was unclear if the other thread was killed too

hiredman21:01:07

if the process that was hosting the repl is still running it is likely the future is still running

jdkealy21:01:17

oh interesting