Fork me on GitHub
#clojure
<
2018-03-29
>
zaphodious05:03:53

Is there a non-verbose way to get a submap with only a few keys out of many?

zaphodious05:03:28

Like, going from a map with {:a "a"} for the entire alphabet to just the keys for the letters in "cup"?

zentrope05:03:24

@achythlook There’s also https://clojuredocs.org/clojure.set/rename-keys which comes in handy on occasion.

siva08:03:58

Any example on how to refresh ~/.clojure/deps.edn and put some exclusions in packages??

seancorfield08:03:14

@konanki.sivaram Not sure what you mean by "refresh" in that context. As for :exclusions, you just put them in the map with :mvn/versions.

siva08:03:16

@seancorfield I did, uncomplicate.neanderthal gives me an error. But the same thing in lein/project.clj does not give any error

seancorfield08:03:52

Show your deps.edn file and the error you get...

seancorfield08:03:07

(the artifact name would be uncomplicate/neanderthal -- not .)

witek12:03:55

Hello, do you have a hint how I get a clojure source file parser? One which does not throw away formating (spacess, new-lines, etc)? I need to read a clj/cljs/cljc file in Clojure+Clojurescript, make some changes and save it again without destroying the formating. I could not find a library for this purpose. Or could I do this with some Clojure built-ins? Thank you!

sound2gd12:03:23

hi clojurians, May I ask what rpc framework do you use in production?

fmnoise13:03:47

we use our own implementation based on multimethods

sound2gd12:03:32

recently I want to use nodejs to RPC request clj backend services, need some help please

darwin12:03:27

@witek AFAIK the downside is that they use their own reader, so it might not be 100% accurate, if you need highest fidelity you could use tools.reader and jump through hoops to preserve whitespaces during reading, you can abuse cljs.tools.reader.reader-types/log-source* for that. I’ve successfully done it here (at least for cljs): https://github.com/darwin/plastic/blob/master/src/meld/meld/parser.cljs#L32 https://github.com/darwin/plastic/blob/master/src/meld/meld/tracker.cljs#L28

👍 4
bronsa12:03:29

rewrite-clj extracted the tools.reader reader so it shouldn't be too far off

darwin12:03:27

I agree, depends on use-case, I think using rewrite-clj should be first choice under normal circumstances

jmckitrick13:03:57

I just finished reading the results of the 2018 survey. Should I be concerned that as I encourage our team to use more Clojure, that we are going to see it become marginalized in the next few years? Several of the negative comments indicated that could happen based on the community, docs, inaccessibility to newcomers, core direction, etc.

Alex Miller (Clojure team)13:03:05

it’s important to keep in mind that the vast majority of people that filled out the survey did so without entering comments or with positive comments. The relatively small number of negative comments get an outsized amount of attention (imo). Which is not to say that there aren’t things to work on.

ecolui13:03:10

Greetings Mr. Miller. I've been studying

ecolui13:03:18

Clojure since 2015

ecolui13:03:36

I just got my first Clojure job (professionally) two weeks ago

🍾 28
🎉 8
ecolui13:03:50

I'm having the funnest time of my professional career

ecolui13:03:19

Thanks for everything you do for the community.

jmckitrick13:03:38

So, I hear a lot of gripes about docs. I tweeted that I’m willing to help, but no one has taken me up on the offer. So, I’ll ask again: is anyone here working on a Clojure project that would feed me the bits and pieces to help flesh out the docs?

jmckitrick13:03:07

How difficult/complex is the process for review and approval?

jmckitrick13:03:30

I’m pretty sure that although I can get started with something, it will take several revisions to make sure it’s accurate and useful.

Alex Miller (Clojure team)13:03:52

just a matter of filing a PR which I’ll review

Alex Miller (Clojure team)13:03:08

it’s ok if that takes a few rounds

jmckitrick13:03:16

I might dive into some features I’ve not used, so it might take a few more rounds than normal. But that should produce docs better for the beginning experience, I’d think.

john13:03:40

@jmckitrick That's awesome. Ping me if you need another set of eyes on some of those drafts.

jmckitrick14:03:23

So just to clarify, is there more to be done?

Alex Miller (Clojure team)14:03:49

prob better to have this discussion on the issue, but that is just an example of syntax, would be better to document #inst and #uuid in particular elsewhere as they are provided in core. #inst has a wide variety of formatting options as well.

Alex Miller (Clojure team)14:03:07

should be under /reference somewhere

Alex Miller (Clojure team)14:03:22

that’s good starting text

Alex Miller (Clojure team)14:03:54

beyond that, the code is probably the next best place for information

robert-stuttaford14:03:31

@jmckitrick super power: write up what you actually ended up doing in the process of getting a new doc live, and publish that far and wide. let’s show folks how hard this isn’t

👍 12
jmckitrick14:03:57

Good suggestion!

jmckitrick14:03:35

<opens evernote to doc the doc process>

hard-mode 8
val_waeselynck14:03:36

@jmckitrick Having done it for the REPL guide recently, I can testify that the contribution process was pretty smooth, even though that was a big change to the documentation.

👍 8
jmckitrick14:03:37

It really irritates me how beautiful the docs are for some languages, and how such a great language as Clojure has everyone so busy coding, no one is writing docs to keep up.

pesterhazy14:03:57

No-one is an overstatement, there are some wonderful clojure docs, by @alexmiller and others, but more is obviously better!

stuarthalloway14:03:27

@pesterhazy more is not obviously better

stuarthalloway14:03:15

One way people get to “more” is by embedding narratives everywhere they might be needed, rather than linking

stuarthalloway14:03:33

another way people get to “more” is incrementally addressing singular complaints rather than stepping back and re-organizing

stuarthalloway14:03:53

in those two cases more is not better

sveri14:03:00

Hi, is it possible to create a library that has both clojure code and clojurescript code + a external javascript dependency?

jmckitrick15:03:51

@alexmiller @john Do I ‘assign’ you guys, request your review, or something else?

Alex Miller (Clojure team)15:03:19

I’ll see a notification for any pr you create, but also feel free to explicitly request a review

urzds15:03:52

Is there a tool to extract a list of environment variables that are being read from our code through calls to @weavejester's environ's env function? Or maybe even a similar library that allows to specify a documentation string and default values and generates --help output and possibly *roff / mandoc / CommonMark / MarkDown?

john15:03:15

@jmckitrick you can just ping me here on slack and direct me to any docs you want me to review. You can assign to me in github as well, either way.

lwhorton15:03:12

hmm, if I introduce a macro that requires another namespace as part of it’s output, is there a way to make sure the namespace that invokes my macro doesn’t also have to require the namespace?

(defmacro foo [args]
  `(do (some.namespace/do-foo ...)
)
Wouldn’t this require some.namespace to be required in the call site?

lwhorton15:03:08

or would my macro have to dynamically require the some.namespace as part of its output?

vikeri15:03:10

Can I somehow declare a dependency on a non clj(s) file? My use case is that I have a macro and it slurps a file and sets a var. If the file is updated the macros are naturally not recompiled. Can I somehow make that happen? I know I could by using a clj file instead of a normal file but that feels yucky for config. If possible I’d gladly use an edn file.

richiardiandrea15:03:44

Don't know the answer to that,but I wanted to raise a warning because this usage is now discouraged in cljs. Macro could be cached (are not atm, only core is)

4
richiardiandrea15:03:45

Actually sorry for the off-topic 😄

john15:03:56

@jmckitrick nice work on the data literals docs! That's definitely going to be helpful for new folks.

dominicm17:03:09

What's the correct way to extend a protocol for hash maps generally?

Alex Miller (Clojure team)17:03:34

Usually not a good idea but can extend to clojure.lang.IPersistentMap

jcr17:03:12

No way to specify priority if more than one impl matches though (if I'm not mistaken?)

Alex Miller (Clojure team)17:03:52

right - generally it’s best to scope any protocol extensions as narrowly as possible, preferably only to concrete types

bronsa17:03:42

why not a good idea @alexmiller?

Alex Miller (Clojure team)17:03:13

because IPersistentMap is a very generic interface which applies to all maps and record types

bronsa17:03:33

ok but you're not saying that extending a protocol to an interface is a bad idea then right?

Alex Miller (Clojure team)17:03:38

so you are likely to create a situation where you conflict with other extensions and create ambiguity

bronsa17:03:38

that's what I understood you meant

Alex Miller (Clojure team)17:03:04

there is nothing wrong with extending a protocol to an interface

bronsa17:03:11

right, cool

bronsa17:03:16

I get what you mean then

Alex Miller (Clojure team)17:03:53

my “Usually not a good idea” is in particular targeted at “extend a protocol for hash maps”

bronsa17:03:12

(i know rich doesn't like it)

Alex Miller (Clojure team)17:03:29

Rich and I are at odds on that one

bronsa17:03:45

I think it's fundamental for allowing proto->interface extension tbh

bronsa17:03:00

but it's true that it's rarely needed

Nicolas Boskovic18:03:01

I got a question; I have an array of integers I want to convert to a byte[] of the ints equivalent hexes

Nicolas Boskovic18:03:49

So from [60, 129...] I want to go to [3c, 81...]

Nicolas Boskovic18:03:11

but not as Clojure's PersistentVector, as a Java byte array

benzap20:03:58

Man, the clojure community is a strange beast

benzap20:03:32

I wrote a blog post trying to advocate for it's use, and it seems almost like it was a wrong course of action

turkkam20:03:11

link pls 🙂

turkkam20:03:28

all i see is awesome blog post that is telling me that Clojure is awesome 🙂

benzap20:03:04

haha, alright 👍

benzap20:03:15

Maybe i'm just being critical

justinlee20:03:41

I love this post. Super concise without being terse. Great examples. Attractive layout. Did you get criticism from folks? I don’t see a comments section.

turkkam20:03:45

yeah maybe 🙂, i think posts like that are good for the Clojure community

tbaldridge20:03:11

@U0670BDCH I remember this article, what bad feedback did you get?

john20:03:24

nice! might want to add your blog here: https://github.com/ghoseb/planet.clojure

👍 4
john20:03:43

(if you haven't already)

tbaldridge21:03:01

@U0670BDCH the one bit of feedback I have (that showed up on reddit a bit) is that lisps and Clojure are kindof jacks of all trades. They can do all these things, but they're not the best at any of them

👍 4
tbaldridge21:03:10

except concurrency, Clojure is really good at that

tbaldridge21:03:29

core.logic is good, but not an amazing logic programming language

benzap10:03:29

@U8ES68TGX I have no comments section, so I kind of rely on reddit post comment sections. I'm trying to keep the blog posts minimal. Maybe I should start linking the reddit comment section in the blog posts?

benzap10:03:16

I agree with @U07TDTQNL, lisps have the advantage and disadvantage of being expressive

benzap10:03:36

@john Interesting site! I'm going to try and get a few more blog posts out before I consider it a clojure reference, i'm hoping to pump out some more posts soon

markw21:03:31

Question: I came across a stackoveflow post yesterday asking why recur wasn't working but standard recursion was. Turned out the problem was that recur doesn't gather rest args into a seq... which is documented behavior and highlighted in the clojuredocs sample below: `; Note that recur can be surprising when using variadic functions. (defn foo [& args] (let [[x & more] args] (prn x) (if more (recur more) nil))) (defn bar [& args] (let [[x & more] args] (prn x) (if more (bar more) nil))) ; The key thing to note here is that foo and bar are identical, except ; that foo uses recur and bar uses "normal" recursion. And yet... user=> (foo :a :b :c) :a :b :c nil user=> (bar :a :b :c) :a (:b :c) nil ; The difference arises because recur does not gather variadic/rest args ; into a seq.`

markw21:03:55

oops messed up the formatting there - sorry

markw21:03:48

So - I've never had an issue with this before, probably because I only use recur in conjunction with loop, so any gathering of rest args would occur in context of a loop binding

markw21:03:07

It's a total non-issue to me, but it got me wondering why there would be a difference in semantics. I found plenty of material discussing the difference, but not the why. Would anybody be able to shed some light on this?

markw21:03:22

added a properly formatted snippet from the docs

hiredman21:03:42

it is mostly because the code that supports var args and the code that compiles loop/recurs don't know anything about each other

hiredman21:03:15

when you compile a function the varargs support sort of lives outside outside of the function, so by the time the function body begins executing it is passed a collection, an the recur point (basically a jump target) is at the start of the function body

lwhorton21:03:04

you dont need to “call” a macro from in a macro, right? if you emit the macro it will get immediately unrolled right?

markw21:03:50

yeah - if you generate a valid expression it will automatically execute

lwhorton21:03:09

i.e (defmacro foo [] ...) if I just emit this

(defmacro bar [] `(do (foo ...))
then I don’t have to even escape it, right?
`(do ~(foo …))`

markw21:03:26

@hiredman not sure I follow

markw21:03:58

if you pass multiple args they are gathered at call time

hiredman21:03:46

they are gathered in some machinery in clojure.lang.AFn between the call site and before the actually function body starts executing

markw21:03:40

OK .. maybe i should just look at the source for that and it'll be more clear

hiredman21:03:48

I doubt it 🙂

markw21:03:56

i've never really encountered a problem with this before, it just caught me by surprise when reading the docs

markw21:03:07

seems inconsistent for such a remarkably consistent language

hiredman21:03:16

but recur being a jump back to the top of the function body doesn't pass through that machinery

markw21:03:39

ok that makes sense actually

markw21:03:08

is it fair to say it's more like going to the top of the body as opposed to re-passing arguments

markw21:03:17

e.g. sort of like javascript hoisting

markw21:03:51

you just re-bind vars locally at the very beginning of the body, but never call it again

markw21:03:43

@lwhorton your first example is correct

markw21:03:17

@lwhorton the macro generates code (text) that is then evaluated after generation

markw21:03:41

thanks for clarifying

lwhorton21:03:09

:thumbsup: that’s good, thanks. my issues is elsewhere (to the macro bookstore!)

markw21:03:35

there is a pretty good one "mastering clojure macros"

markw21:03:46

i haven't read it all yet, but it's been helpful so far

markw21:03:26

most importantly it's concise with lots of code samples, not a tomb of fluff chatting you up 🙂

schmee22:03:47

:thumbsup: for mastering clojure macros, really useful book