Fork me on GitHub
#clojure
<
2017-09-14
>
vinai04:09:12

Is there an idiomatic way to get a file-seq based on a io/resource for a directory in resources/ in a uberjar? It works in a lein run/repl session, but when bundled in a jar the file-seq only contains the path to the directory, not the contained subdirectories and files.

noisesmith04:09:05

you can't get files from inside a jar, you can only get resources, you can make something that acts like file-seq, but file-seq itself isn't an option

noisesmith04:09:24

I mean, I guess you can unzip the jar and then get a file-seq, but that's not likely what you want

vinai04:09:34

no, that's not what I want šŸ™‚

vinai04:09:10

Thanks, I'll dig further how to list files in a resource directory and build something like a resource-seq

vinai04:09:31

Nice šŸ‘

vinai04:09:35

Thanks a lot

odie09:09:48

What are peopleā€™s thoughts on the current state of the clojure api docs?

yogidevbear09:09:03

I know @U04V70XH6 has some thoughts on this and there has been a lot of work recently on updating docs at clojure-docs. For example, I believe the docs for jdbc were updated about a month or two back (http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html)

hmaurer11:09:59

As a beginner I have found Clojureā€™s documentation overall to be very good

hmaurer11:09:07

especially

odie11:09:44

It certainly is possible to find what youā€™re looking for on clojuredocs. šŸ˜ƒ

odie11:09:13

The user submitted examples help a lot, for sure.

hmaurer11:09:37

@U05380FG9 the ā€œsee alsoā€ section has also been tremendously useful to me as a beginner learning clojure.core

hmaurer11:09:45

It helped me discover many functions

hmaurer11:09:05

or quickly find functions which I forgot the name of

hmaurer11:09:19

for example yesterday I remembered there was a function to set the value of an atom but forgot its name. I searched for swap! (which I remember was the function to transform the value of an atom) and looked in see also, which contained reset!, the function I was looking for

hmaurer11:09:34

a bit of a silly example, but still

tbaldridge13:09:10

There was a discussion about this on the Clojure mailing list

tbaldridge13:09:05

two key takeaways (imo): 1) docs can be separate from code. No reason to tie doc updates to the main clojure distro. 3rd party docs are welcome! 2) Clojure loves data, can we keep it that way? Why not keep all this documentation in a data format (instead of markdown which is not data, but text). Seems like a combination of clojure core specs, doc strings, comments, and proper formatting could do a lot.

tbaldridge13:09:15

the bits are all there, just needs a bit more editor support

odie01:09:53

so about that 2nd part, keeping data as dataā€¦

odie01:09:27

I donā€™t completely understand that pointā€¦

odie01:09:57

doesnā€™t good documentation necessarily have to be text?

odie01:09:12

it can be enriched with data, I guess?

seancorfield01:09:00

@U05380FG9 He means that the system of record should be data -- and then all sorts of tools can generate whatever type of docs them want from that data.

odie01:09:08

I understand the value of consumable/transformable dataā€¦ but stillā€¦ suppose I want to end up with some documentation that looks like this: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

odie01:09:54

Most of the main content of that page is straight text and can be represented well as some kind of markup language. How might that be represented with other kinds of data?

odie01:09:12

I want to help with improving the docsā€¦ but Iā€™m honestly having trouble understanding the point being made in the mailing listā€¦

seancorfield01:09:13

Look at http://clojuredocs.org ā€” http://clojuredocs.org/clojure.core/select-keys ā€” thatā€™s drawn from data: the metadata of all the namespaces and the functions, and some additional data added from a database, entered as examples by community members.

seancorfield01:09:46

The only thing on that page drawn from the select-keys function is the docstring ā€” and it says Available since 1.0 (from metadata on the function).

seancorfield01:09:42

Members can contribute to http://clojuredocs.org and members can contribute to http://clojure-doc.org (longer form tutorials and stuff about the ecosystem rather than core Clojure).

seancorfield02:09:27

In addition to the raw data inherent in the Clojure core code itself (namespaces, symbols, metadata, docstrings), there are also all the core specs which can be used to generate all sorts of additional documentation (folks havenā€™t done anything with this yet, beyond the updates to the doc function shows specs as well as docstrings).

seancorfield02:09:35

http://clojuredocs.org probably has the lowest bar for contribution: just login and start adding examples and see-alsos etc; the underlying infrastructure is on GitHub and accepts PRs if you think anything needs changing in the code. Next would be http://clojure-doc.org which is entirely managed on GitHub and the ā€œguidesā€ team are happy to accept PRs (we need to automate the publishing after a PR is merged thoā€™). Finally thereā€™s http://clojure.org itself, for which you need to sign a CA (to assign copyright of your contributions ā€” but you can do that electronically) and then submit PRs.

odie02:09:21

I want to ask about the core specs stuffā€¦ but lemme ask this one firstā€¦ Is there something wrong with trying to inject more detailed docstrings (maybe in a markup lang) for tools to look up?

seancorfield02:09:06

And then thereā€™s docstrings in Clojure/core itself which are treated as ā€œcodeā€ and therefore need a CA and a patch, rather than a PR.

seancorfield02:09:17

@U05380FG9 If the docstrings used markup, then all tooling, even the bare bones REPL, would need to deal with it. Thatā€™s a bad idea. And thatā€™s why the Clojure/core folks are so against that.

odie02:09:56

right~ but if we have a separate repository of just ā€œbetter docstringsā€, but community would be able to actively participate in making it betterā€¦

seancorfield02:09:07

The docstrings all end up in the clojure-x.y.z.jar file so thatā€™s another reason for not wanting more detailed docstrings in the code.

odie02:09:29

add in some tooling to look up docstrings from that alternative sourceā€¦ wouldnā€™t that work?

seancorfield02:09:52

Sure, and anyone is welcome to set up a community project with ā€œbetter docstringsā€, in some form that tooling can use (data).

seancorfield02:09:56

A web site that could yield arbitrary documentation in plain text, markdown, rendered HTML, etc from a GET /clojure/java/jdbc/query?format=ā€¦ style URL would be great. Any volunteer or group of volunteers could do that, and seed it with the default docstrings until community members edited them.

odie02:09:29

sounds good šŸ˜ƒ

seancorfield02:09:33

Iā€™ll observe that I moved the java.jdbc docs out of the contrib repo to http://clojure-doc.org specifically to get them out of the CA/patch process and into an open community GitHub/PR process. I did that ages ago. But almost no one has ever contributed to those docs, beyond me and (recently) one other community member.

odie02:09:09

and thank you for running that project!

seancorfield02:09:45

Allowing the community to maintain external documentation is one thing ā€” and itā€™s a good thing ā€” but actually getting people to contribute is something completely different. Lots of people love to complain about the state of Clojure documentation, but when it comes down to actually making it betterā€¦ crickets šŸ˜

seancorfield02:09:00

(and since some folks have been complaining about the docs for years now, but community contribution levels remain low, youā€™ll understand why the Clojure/core folks tend to be a bit unsympathetic to the complaints these days šŸ™‚ )

odie02:09:56

yeah~ wellā€¦ working on documentation probably doesnā€™t seem very appealing to people, unfortunatelyā€¦ but it definitely is necessaryā€¦

odie02:09:22

I looked into clojure.core with the other day. It reports there are 500+ public functions in there. Itā€™s a bit daunting to have to replace that many docstrings.

seancorfield02:09:34

I value the time the Clojure/core team spend on the code ā€” on Clojure itself and the power it provides us all. I donā€™t want them to ā€œwasteā€ time on documentation instead. But Iā€™d sure like to see more community members contribute to the various documentation sites.

seancorfield02:09:58

@U05380FG9 Youā€™d generate an initial version from the default docstrings in the core ā€” not much effort ā€” and then provide an editing mechanism for the community to expand those. It would be a slow, incremental replacement over time.

seancorfield02:09:20

Thatā€™s pretty much what http://clojuredocs.org does.

odie02:09:33

I actually hacked together something that will highjack CIDERā€™s doc requests and inject it with new docstrings if availableā€¦

odie02:09:55

itā€™s not fancy and itā€™s not a web serviceā€¦ but I guess itā€™s a startā€¦

odie02:09:24

back to the core lib specs you mentioned earlierā€¦

odie02:09:39

has the core lib been specā€™ed? where can I get a hold of that?

seancorfield02:09:50

https://github.com/clojure/core.specs.alpha ā€” mostly macros right now I think ā€” thatā€™s part of Clojure 1.9 alphas (we have Alpha 20 in production).

odie02:09:09

okay~ having any kind of type info on the function params would help a whole lot. I canā€™t remember the number of times when I wondered ā€œwhat kind of stuff will that function actually accept?ā€

odie02:09:42

Being able to play with the function in the repl definitely helps. But, that seems to introduce unnecessary friction into the dev process and is likely to penalize newcomers to the language.

odie02:09:56

Will look into generating function param documentation using core.specs.alpha. šŸ˜ƒ

odie02:09:23

looked at Racketā€™s api docs the other dayā€¦ https://docs.racket-lang.org/collections/collections-api.html Itā€™s rather nice that each functionā€™s prototype is clearly outlined above any additional explanation.

odie02:09:59

I guess instead of ā€œprototypeā€, I should say, function signatureā€¦

seancorfield02:09:21

I guess Iā€™ve gotten used to just pressing ctrl-alt-, d when I want to see docs (inline, in ProtoREPL). I tend to only have a few lines of the REPL open at the bottom of the screen and do everything in files and have ProtoREPL display inline results in the editor. Iā€™ve also gotten used to Clojureā€™s ā€œlack of typesā€ so there are a lot of functions you donā€™t really need to know ā€œwhat kind of stuffā€ they will accept, if theyā€™re written for a sequence, for example.

odie03:09:14

yeah~ I like the lack of strict types and the flexibility that comes with it. Still, when I first get acquainted with an api/function, it can get a little confusing.

odie03:09:07

For example, the api docs for ā€˜ns-publicsā€™ says: ------------------------- clojure.core/ns-publics ([ns]) Returns a map of the public intern mappings for the namespace.

odie03:09:16

at first glance, I have no idea what it actually acceptsā€¦

odie03:09:16

do I pass it a string? do I somehow lookup an ā€˜nsā€™ (as the param name suggest) first?

odie03:09:40

oh, I can just pass it a symbol?

odie03:09:55

yeah~ The repl is very good for exploring an api. But, I think a little clarity in the docs will go a long way.

buzzdan09:09:51

hi all šŸ™‚ does anyone knows about a repl wathcher something like npm's nodemon that watch my files and when i change anything it reloads the repl ? same goes for tests, lintign etc...

tap09:09:59

For webserver, ring has reload middleware https://github.com/ring-clojure/ring/wiki/Reloading. But I would suggest you to reload manually with help from tools like https://github.com/weavejester/reloaded.repl or https://github.com/weavejester/integrant-repl

odie11:09:52

You might also want to take a look at https://github.com/danielsz/holygrail

odie11:09:49

itā€™s got a setup where itā€™ll refresh your repl automatically on file saveā€¦ it helps to keep your repl in the same state as your source fileā€¦

nha13:09:28

if you use boot there is a watch task.

rahul.sns11111:09:37

for variable names matching exactly with some builtin core function name, is there some naming convention to be followed for naming such variable? eg, I have a function which accepts a parameter which represents name. I can not call it name as it will conflict with the clojure.core function name. I have been using alternate names / short forms till now, wanted to check if there is some convention.

odie11:09:01

How about just using something like name#?

rahul.sns11111:09:41

seems good, although it seems more like variable defined in a macro

noisesmith16:09:22

calling it name is valid, but you can also qualify it, as in foo-name (where I canā€™t guess fooā€™s real name without knowing more about your code)

karlstefan11:09:14

Anyone here got experience with lacinia? I'm writing a graphQL proxy for a REST api, and I'm having problems traversing the REST endpoint and building

karlstefan11:09:26

.. the data structure

karlstefan11:09:35

The backend has data in the following format {object { children { list of objects } }, which can go on for a long time. However, I am only able to retreieve one level of children. Any suggestions?

hmaurer12:09:08

@karlstefan try the #graphql channel

karlstefan12:09:33

Thanks šŸ™‚

jetzajac13:09:50

Hello everyone. We had a hard time implementing custom transducer that tried to supply itā€™s initial value. If we take a look at transduce impl: (defn transduce ([xform f coll] (transduce xform f (f) coll)) ([xform f init coll] (let [f (xform f) ret (if (instance? clojure.lang.IReduceInit coll) (.reduce ^clojure.lang.IReduceInit coll f init) (clojure.core.protocols/coll-reduce coll f init))] (f ret)))) We can see itā€™s 3-arity version invokes reducing function and passes it as initial value to 4-arity. I see the problem here. If we see Transducer as a transformer for reducer then we should never invoke f ourselves here. We should have passed it to xf, get the real resulting r-f and invoke this with zero arity only after transformation. Could anyone please clarify on this? Is it some misunderstanding on my side or itā€™s just a bug?

Alex Miller (Clojure team)13:09:29

Transducers shouldnā€™t supply an initial value

Alex Miller (Clojure team)13:09:44

the transducing process does that

jetzajac13:09:54

But what is itā€™s zero arity is for?

Alex Miller (Clojure team)13:09:08

itā€™s to pass through the transducer chain

jetzajac13:09:47

I canā€™t see it being invoked in transduce at all. Am I wrong?

jetzajac13:09:33

As far as I can see arity-4 is to be implemented with 3: (defn transduce2 ([xform f coll] (let [fā€™ (xform f)] (fā€™ (reduce* fā€™ (fā€™) coll)))) ([xform f init coll] (transduce2 xform (fn ([] init) ([r i] (f r i))) coll)))

cddr15:09:38

Is this a surprise to anyone?

(clojure.data.json/read-str "{\"foo\": 43 \"bar\": 42}")
=> {"foo" 43, "bar" 42}
Note the missing comma in the json input

tbaldridge15:09:42

data.json is a bit of a barebones json parser, so it doesn't surprise me. But I'm not sure why I'd ever care if bad JSON got parsed correctly?

cddr15:09:55

Authoring test data that ends up working in clojure and then banging one's head against the wall trying to figure out why it doesn't work in another language? (or even after porting to cheshire maybe)

hiredman18:09:46

in a macro use (new Whatever ...) instead of creating the Whatever. symbol

csm18:09:07

same error replacing ~ctor-sym with new ~type-name

hiredman18:09:34

unrelated tip

hiredman18:09:52

the error is because you have the defn inside the let

csm18:09:53

hmm, so probably make the recycler# a var instead

hiredman18:09:58

actually, for deftypes using the factory function ->Whatever is prefered to using the construtor directly

csm18:09:35

I was going to redef ->Whatever to do something different

hiredman18:09:02

I would leave it, make mk-sym your special constructor name, and leave ->Whatever as the standard thing as an escape hatch so someone who doesn't want your special thing can avoid it

csm18:09:09

well the goal was to replace usage of defrecords with this (and add ILookup etc to the type), and a lot of the code (which uses ->Whatever to make thing and does dispatch on (type thing)) would stay the same

ghadi20:09:30

defrecord already has ILookup

csm21:09:37

But the idea was to make a ā€œrecyclableā€ type, where there are mutable fields behind the scenes, and the ILookup would return the current value, not whatever mutable container that held that value

ghadi21:09:48

gross šŸ˜‰

csm22:09:38

I'm at the point where GC thrashing is my biggest issue. Time to try out gross stuff šŸ˜›

kevinbheda19:09:15

Having hyphen in folder name gives error but when i rename test_utils to testutils it works

java.lang.Exception: namespace 'com.pay.boomerang.config' not found after loading '/com/pay/boomerang/config', compiling:(com/pay/test_utils/helpers.clj:1:1)
there has been a similar question posted here but no actual reason of the problem -> https://stackoverflow.com/questions/12718658/why-does-java-complain-that-namespace-is-not-found

seancorfield19:09:22

Clojure, being a Lisp, allows - in symbol names. Java, the compiled target host environment, does not. So when Clojure compiles com.pay.test-utils.helpers, it produces a Java package com.pay.test_utils containing a class helpers. The file system must conform to Jaya's view of packages so it must be com/pay/test_utils on the file system. Does that answer your question?

josh.freckleton20:09:29

In compojure-api is there a way to mark a field in a schema as "deprecated" so that it shows up in the swagger UI?

oskarkv21:09:22

I am trying to get the *cider-error* buffer to always display in the same frame. Right now it opens in the last window it was open in, which might be in another frame. I recently learned that there is a variable display-buffer-alist that sounds like it might be useful. But it sounds like display-buffer is not what's being used, since it displays the buffer without selecting it, but when an error occurs the error buffer is selected. Then there is pop-to-buffer, switch-to-buffer, etc. Anyway, does anyone know how I can get cider to always display the error buffer in the same frame, but not the same window?

noisesmith21:09:49

@oskarkv when I used emacs winner-mode saved my sanity - it gives you a history where you can undo and redo all changes to buffer layout in your pane https://www.emacswiki.org/emacs/WinnerMode - it comes standard with emacs you just need to turn it on

oskarkv21:09:18

@noisesmith I'll check it out, thanks.

oskarkv21:09:13

For now I figured I can delete the old buffer with an advice before cider tries to switch to it

seancorfield02:09:35

http://clojuredocs.org probably has the lowest bar for contribution: just login and start adding examples and see-alsos etc; the underlying infrastructure is on GitHub and accepts PRs if you think anything needs changing in the code. Next would be http://clojure-doc.org which is entirely managed on GitHub and the ā€œguidesā€ team are happy to accept PRs (we need to automate the publishing after a PR is merged thoā€™). Finally thereā€™s http://clojure.org itself, for which you need to sign a CA (to assign copyright of your contributions ā€” but you can do that electronically) and then submit PRs.