Fork me on GitHub
#clojure
<
2020-03-03
>
seancorfield00:03:37

How many folks test all the examples in their README files? Do you automate that? Are there any alternatives to midje-readme for that sort of thing?

Crispin02:03:37

yes. I do it manually copy and paste when preparing a new release.

seancorfield03:03:52

@U1QQJJK89 Would you use a clojure.test-compatible tool that could automate README example testing appeal to you?

Crispin03:03:28

yes but it would need to test shell command invocation. here I cd into the quickstart directory of the project and run commands: https://github.com/retrogradeorbit/bootleg/blob/master/README.md

Crispin03:03:09

in other cases I would be testing clojure code directly though

seancorfield03:03:18

Haha... okay, that's an interesting use case... I was talking more about pure Clojure code in the readme, in the context of the project itself, so it would only pay attention to chunks of code wrapped in three back ticks and clojure 🙂

seancorfield03:03:59

I've used midje-readme on a couple of projects (and I do not like midje!) and it seems to be the only game in town and it does have several caveats 😕

Crispin04:03:47

selecting the backtick blocks by clojure annotation would work. shell blocks could be handled seperately.

seancorfield04:03:29

True. Not sure the latter is in my scope right now but it's an interesting option to consider.

Crispin04:03:19

Just solve the clojure case, and leave the shell case for my pull request 😉

parrot 1
💯 1
flowthing15:03:30

I've been working on a thing that can turn Clojure code blocks in Markdown and AsciiDoc code blocks interactive: https://github.com/eerohele/useless I've shelved it for the moment, probably mainly because I don't know whether it's actually useful for anyone (hence the name). You could use it to test code blocks in your README, though.

flowthing15:03:07

(I realize it's not exactly what you're looking for, though.)

flowthing16:03:24

Oh, I see you already went ahead and made a thing of your own — cool!

seancorfield16:03:29

Yeah, the first version is fairly simplistic. I dreamed of some richer approaches overnight so seancorfield/readme will evolve quite a bit over the next day or two I suspect 🙂

seancorfield18:03:32

seancorfield/readme {:mvn/version "1.0.12"} -- https://github.com/seancorfield/readme -- I ended up writing a thing to turn README files into tests 🙂

4
👀 1
didibus02:03:57

Anyone tried to use http://pitest.org/ with Clojure

deep-symmetry03:03:19

@borkdude hats off to you! I had written my own tiny Clojure-based DSL for generating SVG diagrams as part of the Asciidoctor/Antora pipeline, and as much fun as I was having implementing the various special forms, someone pointed me at sci and I ripped out my own code and integrated yours, producing a much more feature-filled, yet still safe and usable in a JavaScript pipeline, language. 🔥

introom04:03:48

there is no =print-method= in the core api page https://clojure.github.io/clojure/clojure.core-api.html

introom04:03:54

is that suppose to be an api?

introom04:03:06

and also stuff like print-simple

alexmiller04:03:56

print-method is not included because it's not doc'ed, but it probably should be. it's really more of an spi method than api (for hooking into the print system)

alexmiller04:03:40

ditto print-dup which is equally as important

alexmiller04:03:55

things like print-simple and print-ctor, probably not but I'd have to look at it more

introom04:03:03

thanks for your work.

manu11:03:54

Hi all, I have a REST application in clojure and I want to use oauth2 to authorize incomming requests. can you suggest some libraries?

1
orestis12:03:05

What’s the best way to handle a java.lang.Iterable that blocks forever - (representing a stream of changes from a mongo database)? Obviously need to spawn it in a separate thread but not sure if I should just use doseq — and how to deal with cancellation…

vemv12:03:48

wdyt of this pattern?

(def q (queue-of-your-choice))

(def enqueuer (future
                (while (not (-> Thread/currentThread) .isInterrupted)
                  (let [v (take-value-from-mongo)]
                    (put! q v)))))

(comment (future-cancel enqueuer))
(queue-of-your-choice) could be java blockingqueues, or a core.async chan etc Idea being, you deal with the mongo iterator in a very delimited part of your codebase, and the rest of the codebase consumes a vanillla queue, with more familiar semantics, and importantly with blocking/timeouts so that production and consumption don't run at disjointed rates

orestis13:03:42

That’s a good call — and I found out that Iterable can give me an Iterator which has a plain next call.

👍 1
orestis12:03:34

doseq seems to be doing the lazy chunking of 32 items at a time, which I don’t want, I want to consume the next time as soon as it’s available.

👀 1
restenb13:03:04

i need to write a bunch of lines to a file generated from application data ... is there a "nicer" way than opening an io/writer and chaining calls to (.write w stuff) with (.write w "\n")?

deep-symmetry13:03:02

Can’t you just use

(binding [*out* w]
  (… normal Clojure print, println, et. al. calls …))

introom14:03:07

what’s the purpose of emphasizing free of side effects?

introom14:03:20

Usage: (iterate f x)
Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects

bronsa15:03:35

f x may be invoked multiple times

deep-symmetry15:03:48

And at unpredictable times because of chunking, no?

hindol15:03:50

I don't think it will be called multiple times. But delayed and chunked calls are a possibility.

hindol15:03:18

In short, don't mix lazy sequences and side effects.

manutter5115:03:24

Looks like iterate just wraps a call to clojure.lang.Iterate/create, which is an interesting read https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Iterate.java

hindol15:03:41

Thanks for the link. Forgot that iterate is not chunked.

bronsa15:03:36

it can be invoked multiple times -- the reducible path doesn't cache https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Iterate.java#L65-L75

bronsa15:03:12

I thought I was going crazy for a second

alexmiller15:03:40

yeah, the result of iterable can be accessed as a seq and reduced over and those two paths do not share values

alexmiller15:03:58

doing both is probably uncommon

MatthewLisp16:03:33

does clj-http auto decode base64 on the response body?

dchelimsky16:03:50

Of course, that's just a suggestion. I could be missing something.

MatthewLisp16:03:29

that's weird, because on the browser i receive an encoded body resp, and with clj-http i receive it decoded

dchelimsky16:03:45

In the browser? So cljs-http?

MatthewLisp16:03:14

no, i mean, i make the request with Firefox, navigating the page

MatthewLisp16:03:50

and using the dev tools i can see it returning a Base64 string as response body

MatthewLisp16:03:28

but the same request with same headers made in clj-http returns the same content but it's already decoded

MatthewLisp16:03:56

the problem is that in this decoding process it uses the wrong encoding format, and i lose some characters such as ^ ~ `

dchelimsky16:03:12

Are you certain that the server is sending the same Base64 string when you're calling from a Clojure runtime? Any chance there are differences in the request, like Accept headers, etc?

MatthewLisp16:03:08

i literally copied the same ones that the browser request is using

MatthewLisp16:03:25

i didn't said but, the response is a CSV file

MatthewLisp16:03:38

maybe Firefox is doing something and encoding this as base64

dchelimsky16:03:26

Could also be happening in deps of clj-http

dchelimsky16:03:49

Lots of possible places where the requests and/or responses differ.

MatthewLisp16:03:03

all of that wouldn't be a problem if i could take this string that i receive on CLJ-HTTP and get back those missing characters ~` instead i get some ? characters in place of them, this is ruining my parsing process

noisesmith16:03:53

could it be that the implicit stringify is using the wrong text encoding?

MatthewLisp16:03:00

clj-http add's lot's of headers for us, maybe something is going on there

MatthewLisp16:03:27

yes @noisesmith that's what i think, but where is this implicit stringify?

noisesmith16:03:49

if you use the :as :input-stream option to clj-http, you'll be able to consume and convert it in whatever way you like

👍 1
noisesmith16:03:06

let me look up the actual option...

MatthewLisp16:03:19

ok! i'll give it a try

noisesmith16:03:01

the option is {:as :stream} - then it's your job to consume the stream, convert, etc. etc.

MatthewLisp16:03:52

i'll try to use slurp in it passing the right encoding

noisesmith16:03:54

there's also {:as :byte-array} which also won't do any text conversion and might be more convenient

noisesmith16:03:25

eg. the base64 decoder that comes with java takes a byte-array

MatthewLisp16:03:51

assuming this will return the base64

MatthewLisp16:03:58

well let's see

MatthewLisp17:03:04

found a way much more simple

MatthewLisp17:03:30

{:as "iso-8859-1"}

👍 1
MatthewLisp17:03:40

then it came on the right format

matthewdaniel19:03:32

I have a coworker that wants to learn functional programming concepts but in javascript/typescript language. Has anyone come across a good course or book?

Nir Rubinstein20:03:17

You can have FP concpets in almost any language (higher order functions, expressions vs. statements, referential transparency etc.), but some languages "lend" themselves to it much better than others. For me, the crux of the matter lies in immutability which JS or TS don't have so it'll be much harder... If he wants to learn it on the FE side, he can try Clojurescript/Elm/Purescript etc.

matthewdaniel20:03:17

I've convinced him that it is worth learning but can't convince him to pick up a new language

Michael J Dorian20:03:57

For what it's worth, lots of people in my local dev group love functional programming in JS. I would say it's the most popular language for functional programming in my tiny town simple_smile

seancorfield22:03:18

@U5136PEE6 Point him at Grokking Simplicity by Eric Normand. It's a work in progress right now but it uses JS to illustrate the concepts and it's really well thought out.

porkostomus11:03:48

And speaking of which, Functional JavaScript by Michael Fogus, while kind of outdated, was a very good read

porkostomus11:03:26

I heard that this is great for functional JavaScript https://github.com/thi-ng/umbrella

MatthewLisp19:03:54

i've tried lot's of them, never had success in trying to learn FP concepts with JS

MatthewLisp19:03:36

because you can mix paradigms, when i tried, things tend to become a mess and i always got lost in the process

Audrius20:03:21

is it possible to write a macro which gets the calling function? I am thinking of using ~(meta &form) implicit macro var and *file* . Maybe it is possible to to combine those variables and infer the calling function. Or maybe there is an other way? :thinking_face:

ghadi20:03:30

what are you trying to achieve?

Audrius20:03:15

@ghadi I want to make log framework macro that shows tha calling function

didibus20:03:09

You can get the calling function from the stack info, but I think it might add quite a bit of overhead

✔️ 1
seancorfield23:03:25

Java 14 brings an option for "helpful null pointer exceptions" -- how might it affect Clojure? See https://clojureverse.org/t/helpful-nullpointerexception-jvm/5556/3 for an example.

parens 2
alexmiller23:03:27

that was my guess when I read about it too

alexmiller23:03:54

in Java, it is certainly better than the message "null" :)

seancorfield23:03:15

Yeah. Some of those messages could be greatly improved by small refactorings of the Java code in Clojure's runtime and/or compiler but I'd be suspicious of those changes slowing Clojure down.