Fork me on GitHub

Hey guys, if I were to write a wrapper function (g) for another function (f), so that (g x y z) is (f "hello" x y z), how should I write it?


Currently, I'm doing (defn g [& args] (apply f (concat ["hello"] args)))

Toby Clemson00:08:46

apply has many signatures such that there's no need to (concat ["hello"] args)

Toby Clemson00:08:10

Instead you can just say (apply f "hello" args)

Toby Clemson00:08:48

Separately, it might be cleaner to do something like: (def g (partial f "hello")

👍 8

Is that the idiomatic way?


To be clear, I want g to always insert a constant "hello" at the first position of the f call, regardless of the number of arguments.


Can I get an opinion? Making a magazine site. There's subscriptions. You gotta pay $5 to read some of the locked material. With locked material, I have a cljs app basically say "hey it's locked" and if you have credentials or session data, it makes an ajax request for the article. Any tips of how to make this robust?


The robustness is in the ability to differentiate a customer that has paid for a resource from one that hasn't. A small jwt id in a cookie or token is one way to do this (simple data, plus verification you set this data, which at least prevents js based hacks)


let them use jwt to prove who they are, then use that id to verify with your db which resources they have access to, etc.


(def g #(apply f "hello" %&)) is how I’d write that @zhuxun2

👍 8
Anik Chowhdury03:08:17

I have used future for multhreading in core-async. Here is the screenshot of my code and error message. I got null pointer exception for using future. If i use just

(async/thread-call (process-data-chan))
instead of
(future (async/thread-call (process-data-chan)))
i dont get any null pointer exception. Can anyone explain me and give me solution about this? I am newbie in clojure and specially in multi threading.


I would write it as (async/thread (process-data-chan))


is process-data-chan nil? does it return nil?


thread-call expects a function as its arg. does (process-data-chan) return a function?


maybe you mean (async/thread-call process-data-chan)?


so you get the exception with future? and not with the bare call? are you sure it's not the other way around (the exception is with the bare call?)


future captures all internal exceptions. They will be raised when you deref the future.

Anik Chowhdury04:08:58

@U1QQJJK89 thanks a lot. I have to write

(async/thread-call process-data-chan)
instead i write wrong one. Actually i want to use go block of core async to do that operation of multi threading which i did with future. But I really find go block hard to understand!


go is the parking form of thread

👍 4

watch hickeys core.async intro talk. Helped me understand it when I was starting out:

❤️ 16

I'm trying out Reagent. One thing bugs me as someone who came from working with React JSX is that the prevailing formatting convention supported by tooling is very line copy-paste unfriendly:


for example, if I were to append a [:li "c"] after [:li "b"], in the following code

 [:li "a"]
 [:li "b"]]


I can't just line copy-paste the last line. Instead, I need to do some minor editing...


Do you guys format Hiccup-like forms with closing brackets in newlines?


 [:li "a"]
 [:li "b"]

👎 12
👍 4

I'd say that this rule from the style guide applies here:


@U051BLM8F, maybe we should change it to say "delimiters" rather than "parens"?


Personally I’m using Parinfer (, it helps a lot for these cases

👍 8

☝️ this, parinfer makes these problems go away!


In emacs (and probably in other editors), you wouldn’t copy the last line in this case, you’d forward select the next expression (which would select [:li "b"] and then copy the selection


you could also in emacs use c-k to kill the last line, which would retain the final bracket and not delete it


or you can use expand-region


c-= inside the form to select it, then copy and paste as usual


(I use paredit in emacs)

David Pham12:08:19

I would like to generate a range of distinct days with Clojure.spec, anyone could help me with it?


I tried asking in #yada but it seems to be rather empty during my normal hours. But I'd appreciate if someone has a resource on getting oauth2 (with google preferably) to work with yada.oauth that they point me at it.

Noah Bogart13:08:10

if i want to conj a bunch of objects onto a vector in a map atom, and i have them in a list, is it better to write a (doseq [obj objects] (swap! v update :key conj obj) or something like (swap! v update :key #(apply conj % objects))?

Noah Bogart13:08:59

that's a cumbersome way of saying: is it "better"/more idiomatic to do a bunch of swap!s or a single swap! with apply?

Alex Miller (Clojure team)13:08:41

the former is N separate transactions (and someone else could be doing the same thing, interleaving the results)

👍 4
Alex Miller (Clojure team)13:08:09

but really you'd probably be better off with (swap! v update :key into objects)

Alex Miller (Clojure team)13:08:36

but be careful with the nil case - into uses a list in that case

Alex Miller (Clojure team)13:08:08

I guess conj has the same problem (since into uses conj)

Alex Miller (Clojure team)13:08:41

into will also automatically use transients if it can (like with vectors)

Noah Bogart13:08:20

oh that's clever, yeah. i'll experiment with into, see if that handles my usecases


I usually guard against the nil case with fnil like so: (swap! v update :key (fnil into []) objects), to make the type of the collection explicit. Can easily swap out the vector in (fnil into []) for a #{} or {} depending on the type one wants.


I'm reading a XLSX file with this java library ( and transforming the HSSFRow objects into a lazy-seq by converting an Iterable interface using iterator-seq


however I get EOF while reading errors from some files


I could not notice any difference in the content of the files that throws this excp.


any chance the lazy-seq escapes the body of the with-open that keeps the resource open?


yes, this is happening


but I should get errors from all the files I process this way, right?


only the ones that aren't realized up to the entries you try to use


iterator-seq chunks, the chunking can hide this error with smaller inputs


(I'm a big non-fan of chunking iterator-seq btw since iterators often imply some kind of side effect even if just extra IO...)


somewhere I have a snippet for non-chunking iterator-seq, but it's not hard to write regardless


I'm connecting some dots here (while running my code, I did a quick re-write to check if this was the problem)


I send each processed row to rabbitmq and I was watching the patterns of the messages received and I noticed some chunks


so itertaror-seq is the one creating them?


yes, it will consume N items at a time, even if you ask for 1 at a time


interesting, is it possible to control this parameter?


nope, it's built into the code


but as I mentioned, rewriting iterator-seq to not chunk is only a few lines of code


(defn iterator-seq [iter] (clojure.lang.RT/chunkIteratorSeq iter)) you aren't kidding

😄 4

doc string and metadata elided


lost my version, but this one is identical


(defn iterator-seq [it]
   (when (.hasNext it)
     (cons (.next it)
           (iterator-seq it)))))


I'd never put an arg list on the same line as a function name, otherwise to the character my version


i'm extremely inconsistent on that. do you have a motivating reason or just your aesthetics?


the doc-string goes between the name and args

👍 4
Alex Miller (Clojure team)18:08:18

If you care about external resource control, you shouldn’t use seqs in the first place


the args on line with function-name thing makes sense in cl, with their doc-string placement

Alex Miller (Clojure team)18:08:28

Use loop or education or something else

Alex Miller (Clojure team)18:08:22

My general of thumb is - if you care exactly how many things get realized and when, then don’t use lazy seqs

💯 4
Alex Miller (Clojure team)18:08:33

As they make no guarantees


that's pretty reasonable


yeah, I like that as a principled approach, but that's in conflict with every professional codebase I've inherited or collaborated on

Alex Miller (Clojure team)18:08:34

Sounds like you’re the common factor ;)


it's like some things in core.async - the design principles work but the way most people seem to adopt them fall into very predictable misuses

Roger Amorin Vieira20:08:39

Hey clojurians, when I start to learn clojure this year I built some basics tests/algorithms, and today I look that repository and think about create a library to be like a group of nice algorithms, that could be useful. So if you want to help me to build this library access the link and lets code: (This repository is noob friendly, so the code sometime isnt the in the best way, if you found some code that can be upgraded, open an issue explaing that, this it's a nice way to help each other to write better code)