Fork me on GitHub
Daniel Shriki07:04:00

Im running a polylith project, and in every component there is ‘resources’ directory, I want to use that folder to save files for tests and load them during tests. I was reading that using should do that but it returns nil. any ideas?


1. you'll get better suggestions if you tell us what you've tried so far 2. resources is usually reserved for files you want to end up in the deployed artefact (jar or whatever). It's better to use a different directory for test-related files, e.g. test-resources. 3. You need to have a :paths/`:extra-paths` entry in your deps.edn, e.g.:


if you do the above and your :extra-paths in your dev alias is, for instance, ["tests", "test-resources"], then (slurp (io/resource "lala.txt")) will give you the contents of test-resources/lala.txt.


But be careful with this. Make sure the names you give to the files are unique because if you have both tests/lala.txt and test-resources/lala.txt you won't be able to access both (I think the latter will override the former but I'm not sure, never tried it).

👍 1
Daniel Shriki11:04:04

tnx for all the useful information 🙏 I do have “resources” under :paths on deps.edn, but maybe it did’t work because I tried to use it from the tests dir? I have a file under "resources/pdf/test.pdf" - and I tried (slurp (io/resources "pdf/test.pdf")) - but io/resources resolved to nil. I’ll try to make “test-resources” and update.


the function is called io/resource, are you sure you don't have any weird typos that's valid Clojure but does the wrong thing?


Can you share your deps.edn?

Daniel Shriki12:04:36

{:paths ["src" "resources"]
 :deps {}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {}}}}

Daniel Shriki12:04:58

(-> "pdf/test.pdf"

Daniel Shriki12:04:54

the alternative is ofcourse to do

(-> "./components/pdf/resources/pdf/test.pdf"


It works for me. You might have to restart your repl.


> maybe it did’t work because I tried to use it from the tests dir what do you mean? where you're calling io/resource from shouldn't matter


What you should be getting:

Daniel Shriki12:04:48

it doesn’t matter form which component the file is located?

Daniel Shriki12:04:06

assuming it’s under /resources on some component

Daniel Shriki12:04:03

but it happens also when I’m not running from repl

Daniel Shriki12:04:59

(when I run clojure.test)


The pdf file is under resources-test. Is resources-test in your :paths key in deps.edn?


i.e., using your previous example:

{:paths ["src" "resources"]
 :deps {}
 :aliases {:test {:extra-paths ["test" "resources-test"]
                  :extra-deps {}}}}

Daniel Shriki13:04:03

I discovered though that when I run ‘poly test’ he works fine, only when I run the test from intellij he has a problem with it


Right, does it work with a barebones clojure REPL?

Daniel Shriki13:04:57

now it is - and the thing that was missing is a link from the main deps.edn on the project to resources -

{:extra-paths [

💪 1
Daniel Shriki13:04:59

thanks a lot for the help and for the patient 🙏

Serafeim Papastefanos14:04:36

Hello friends can you explain me the difference between reduce and clojure.core.reducers/reduce?

Alex Miller (Clojure team)14:04:07

Essentially the latter may be able to happen in parallel

Alex Miller (Clojure team)14:04:29

If invoked on a foldable source like vectors or maps, the reducers reduce will partition the data and reduce each partition, then combine

Serafeim Papastefanos15:04:51

I think the docs mention that we need to use fold in order for the operation to happen in parallel

Alex Miller (Clojure team)16:04:20

most importantly maps are treated differently by r/reduce - it will be a function of (f [acc k v] ) instead of (f [acc kv] )

Serafeim Papastefanos17:04:24

So no real difference?

Serafeim Papastefanos17:04:06

Only fold is useful to run concurrently on specific structures

Alex Miller (Clojure team)17:04:35

well, the reducing function for maps is a real difference. if not that, what do you consider "real"?


I think the other difference, that it calls f with no args if an init is not provided is actually the biggest difference. Reducers were the precursor to transducers. That init function is important when chaining reducing transforms together I believe. Normally reduce instead takes the first arg as the first value for the accumulator and reduces it against the second arg. But r/reducer doesn't do that, thus properly decoupling the target from the source. The reducing function can thus control what collection it needs to collect into by having a zero arity. At least something like that. I think that explains more why there is another reduce in reducer, I don't think just having a reduce that is like reduce-kv for maps would have justified it otherwise.


But I might be getting it confused with transducers, and maybe here it was just people thought a better reduce would be one that calls (f) for the init and always does reduce-kv for maps.

Serafeim Papastefanos04:04:40

thank you both for the answers

Serafeim Papastefanos14:04:49

I read the but couldn't understand the difference :(


Hi, in Ring... sometimes can access the :headers {map} values via keyword, but usually by "string" like "Content-Type" ... can use keywords & strings interchangeably here?


which underlying server are you using? the spec shows that the headers should be downcased string keys • spec: • for the jetty adapter:


that's what I thought. is ring jetty adapter


Thanks for your sleuthing! Still perplexed as to why a keyword would work o.o


I obtained a string: "\\030ethmac=00:19:b8:08:52:d9\\031wifimac=3c:e1:a1:df:dd:e6\\020sn=nt-2026-c192x" I want to split this string on any Java escape literal, but I can't figure out how. Answers/advice appreciated....


You simply provide a regular expression to split on. You can supply literals in it: (clojure.string/split "\\030....\\020...x" #"\\") (spacing for emphasis)


You will get an empty string as the first element in the result vector, based on my test in cljs


["" "030ethmac=00:19:b8:08:52:d9" "031wifimac=3c:e1:a1:df:dd:e6" "020sn=nt-2026-c192x"]


something like that will be the result


If you want to generalize any escape literal then we'll have to think more 😅


Thanks! But yes, I want to split in ANY escape literal.... ATM I use a combination of splits, and also StringEscapeUtils/unescapeJava and it is kind of an unholy mess

Martin Půda19:04:43

It's possible to edit docstring of some function on ClojureDocs, or do I have to suggest edit as Github issue? I'm talking about - I see only "Evaluates test."


Special forms are handled here in the clojuredocs source: So you could open an issue on that repo or send a Pull Request.

👍 1

is there a way to pprint datalog queries?

 [$ ?e :movie/title ?title]
 [$ ?e :movie/year ?year]]


They're just data, so you can use clojure.pprint/pprint:

  '[:find ?title :in $ ?year :where [$ ?e :movie/title ?title] [$ ?e :movie/year ?year]])
 [$ ?e :movie/title ?title]
 [$ ?e :movie/year ?year]]
;;=> nil


I'm guessing the point is: that's not very "pretty"?


Oh, yeah, I probably misunderstood. 🙂


linebreaks on keywords and vectors only?


left as an exercise to the reader 😏

😅 1