Fork me on GitHub
#beginners
<
2023-02-07
>
naxels10:02:44

Hi all, I’m trying to create a function that will generate a collection of collections from an input collection. What i’m trying to do is turn this input: '(10 20 11 30) into all the possible combinations of (range 1 n) with (range 'prev range nr') so output would be: (coll) <- index index (10 20) <- 0 1 (10 11) <- 0 2 (20 11) <- 1 2 (10 30) <- 0 3 (20 30) <- 1 3 (11 30) <- 2 3

Martin Půda10:02:00

(clojure.math.combinatorics/combinations '(10 20 11 30) 2)
=> ((10 20) (10 11) (10 30) (20 11) (20 30) (11 30))

naxels10:02:01

I looked into using that, but seemed a bit overkill & i need them in the specific order

naxels10:02:30

also, when I add another number to the mix, it also needs to generate that in the correct order

naxels10:02:07

so (10 20 11 30 12) also needs to do 0 4 1 4 2 4 3 4 in that order

Martin Půda10:02:19

(defn comb2 [coll]
  (for [x (range 1 (count coll))
        y (range 0 x)]
    [(nth coll y) (nth coll x)]))

(comb2 [10 20 11 30])
=> ([10 20] [10 11] [20 11] [10 30] [20 30] [11 30])
(comb2 '(10 20 11 30))
=> ([10 20] [10 11] [20 11] [10 30] [20 30] [11 30])

naxels10:02:46

wauw! thank you! I got stuck on the [(coll y) (coll x)] part where i tried to do (nth coll y)

Martin Půda10:02:07

If coll is a vector, it will work- you need nth for lists/ sequences.

naxels10:02:38

ah, good to know! thank you very much, this works 🙂

naxels10:02:46

coll is a list in this case

naxels10:02:07

my thinking is to use (for) with 2 ranges to generate this

naxels10:02:38

but so far I’m stuck as (for) would generate it all in 1 seq

pavlosmelissinos15:02:05

Which VS Code plugin would you recommend for just reading/editing edn files? It's for non-Clojurians, so my first thought is that Calva might be overkill but I'd consider it if there are no lightweight alternatives. Would you recommend https://marketplace.visualstudio.com/items?itemName=clptn.code-paredit?

seancorfield16:02:37

I'd probably go with Calva, so you get syntax-aware highlighting, formatting etc. Then at least if any of these folks get curious about Clojure, they can explore it via the built-in Getting Started without needing any other setup.

👍 2
seancorfield16:02:58

Installing that standalone Paredit could lead to conflicts later...

pez16:02:14

That standalone Paredit is much abandoned and indeed can lead to conflicts later.

👍 2
pavlosmelissinos16:02:20

Right, that's a good point, thank you both. Alright, they installed Calva but they still have an issue, I'll follow-up at #calva

👍 2
👀 2
skylize16:02:56

As far as I know Calva is the only extension with any real active maintenance (plus frequent useful updates:man_dancing:).

pppaul21:02:08

if you are interested in paredit, which can be very rewarding to work with, emacs or spacemacs are editors where it has strong support, for decades. it's possible there are other editors with decent implementations. I find it almost impossible to use editors that don't support such a feature, though the learning curve is a bit high.

seancorfield21:02:45

@U0LAJQLQ1 Perhaps not a great choice for "non-Clojurians" who are using VS Code, based on the OP's question 🙂

pppaul21:02:35

it is something OP mentioned

pez21:02:48

For the record. Calva has pretty decent Paredit. Not to the level of Cursive's, but still, pretty decent. Yes, I'm biased, but anyway.

🙂 2
pavlosmelissinos21:02:45

Even though I love emacs, I was specifically asking for VSCode plugins, as my colleagues are already using it and I'm not (yet 😛) trying to evangelize emacs or Clojure to them. Thanks for the recommendations though 🙂

pppaul21:02:43

I didn't know that calva has paredit. I would recommend trying to learn a few common paredit keybindings for your most common issues. for me, paredit has been the most important thing I have learned from my experience with clojure, and I use it on any language that can support the features (js, html, css, elixir, etc...)

pez21:02:30

Calva’s Paredit is sort of Clojure only. It can handle other LISPs as well, but sadly not outside that. It could be made to do it, but so far no one has put in the work needed.

pppaul22:02:52

there are no general purpose paredit tools in vs code? that's too bad. it is very hard to learn, though.

skylize22:02:09

Calva also has very helpful animated docs for learning its Paredit commands. https://calva.io/paredit/

metal 2
seancorfield22:02:38

> Calva’s Paredit is sort of Clojure only Not sure what you mean by that: I use paredit key bindings when editing EDN files in Calva and that works.

skylize03:02:19

I believe this was reference to other lisps, e.g. Lisp.

pez06:02:13

Calva’s structural editor treats EDN files as Clojure.

2
pez07:02:21

> there are no general purpose paredit tools in vs code? Not that I know of. I think most people will come to Paredit from the LISP direction. Most Emacs users will encounter LISP at some points when configuring their editor. For VS Code users, not so much. Unless we can change that with #C03DPCLCV9N. > it is very hard to learn, though. I might have forgotten, but I don't recall it as particularly hard. I was very motivated, though. And I had colleagues who were eager to teach me.

pppaul22:02:38

paredit removes character based code editing, backspace doesn't work in many contexts, you can't just cut and paste at will. you are forced to work with your code at a higher level concept, which is also completely invisible (editor doesn't show you the nodes). I'm surprised that anyone would find this easy. it took me years to get used to it and figure out what paredit concepts I needed to learn to solve all my code editing needs (calva docs help a lot with this). I found myself constantly getting stuck in paredit and switching to text mode to do quick fixes and then go back to paredit mode

pez22:02:45

Interesting. I never get stuck in Paredit... Calva Paredit strict mode only prevents deleting balanced brackets. Maybe it differs there from how Emacs paredit works?

pppaul22:02:27

paredit forces balanced brackets, it won't start the mode if that isn't the case

pppaul22:02:02

I started using paredit 15 years ago, the docs and jargon were fairly confusing. docs had double the features of what is in calva, but you only need to know 5 or so features to do all work efficiently, it's just not obvious which ones are needed. I feel like if you aren't getting stuck in paredit, you know the features very well, or it's not very strict

pez22:02:18

Well, I wrote Calva Paredit, so maybe that's why. 😃

pez22:02:46

But Calva Paredit doesn't behave like you describe. It's there, balanced or unbalanced brackets. It will not always work well with an unbalanced file, but as soon as you get the balance back things are dandy.

pez22:02:17

I talk to a lot of Calva users, often. There are all sorts of problems. Calva still has too many rough edges. But Paredit seldom comes up as something they need help with.

skylize23:02:47

The only thing Paredit forces on you is the balanced brackets. Everything else is strictly opt-in, learn at your own pace. (And at least in Calva, I'm pretty sure you can even turn that off.) You can just use arrow keys, copy-pasta, and backspace with no problems. Or you can start picking up a few Paredit commands here and there, gradually accelerating your productivity by reducing keystrokes. (A stark contrast to Parinfer, which is its own special domain-specific language, that magically changes out from underneath you into &lt;choose-your-lisp-dialect&gt; as you type.) @U0LAJQLQ1 Maybe you just let yourself get overwhelmed by all the options available to you? not realizing that it's perfectly okay to just ignore everything initially?

skylize23:02:26

And since the discussion seems to have firmly planted on "Paredit vs Parinfer", I think I might as well add the point that most of us probably spend way more time editing code than we do writing code. The productivity gains of Paredit are primarily earned during editing, while the gains of Parinfer are primarily restricted to the smaller percent of time spent writing fresh code.

pez23:02:50

Parinfer wasn't even mentioned before you brought it up, was it? 😃

pez23:02:12

In any case. I think we might have struck a pretty good balance with Calva's Paredit strictness. It's not really in the way much. And when it is, pressing alt while deleting let's you bypass the strictness.

skylize23:02:49

> Parinfer wasn't even mentioned before you brought it up, was it? 😃 Oh, whoops. Threads window collapsed previous messages, and I got it confused with another thread that did. facepalm

seancorfield23:02:53

Sometimes I wish Slack had the ability to automatically close a thread to new replies after a day or two :rolling_on_the_floor_laughing:

seancorfield23:02:03

TIL: I can press alt-delete to erase parens without paredit preventing me!

metal 2
skylize23:02:31

I think pez just said that. 😉

seancorfield23:02:29

Yup, I was today years old when I learned that (from @U0ETXRFEW just now!)

pez23:02:32

@U04V70XH6 the only difference between strict and non-strict (aka Cave Man) is that in strict mode backspace/delete protects bracket balance, and alt let's VS Code's default do its work, and in non-strict alt+backspace/delete protects instead and without alt VS Code defaults are used.

2
pez23:02:48

While at it. From the docs: > There is also a setting, calva.paredit.strictPreventUnmatchedClosingBracket, that will help you to not enter unbalanced closing brackets into the code.

pppaul23:02:55

when i talk about paredit, it's in emacs context (that's all i'm familiar with). you can copy and paste in it, but if you paste unbalanced parens, you are screwed and have to undo, or get out of paredit mode and fix things. it's pretty strict, but also doesn't disabled other emacs things that let you break your code, which is why it's common to get stuck. i found the upsides to be very beneficial compared to the downsides, and it seems like calva has made it so there are a lot less downsides, which sounds good. parinfer is a pretty cool idea, but whenever i use it i get completely confused, but that's just because i'm not used to indenting code anymore. @U04V70XH6 does slack let you mute threads?

pez23:02:23

But I run without that extra strict thing, since when I fat finger in an unmatched closing bracket, backspace just deletes i.

seancorfield23:02:31

> does slack let you mute threads? I can turn off notifications for replies to any given thread -- but I meant my comment more in the sense of preventing drive-by comments restarting threads that had already been answered and were "done" days ago.

pppaul00:02:22

@U04V70XH6 you want some threads to be treated like stack exchange Q/As. i think that would be a neat feature. i assume that groups like this are using slack in a way that isn't really intended, though i'm not sure how slack is intended to be used.

seancorfield00:02:15

Zulip lets you mark threads as "solved" (or something similar) which is something I'd like in Slack. And, yeah, the Q&A sites tend to have that -- as does http://ask.clojure.org -- and so do some of the forums, such as http://clojureverse.org -- which I think all serve different purposes and different audiences. I've hoped, many, many times over the past few years, that this community would migrate to Zulip so we wouldn't be locked into a corporate system (and rely on the generosity of Slack Inc specifically for the Pro plan we're on) but lots of folks like Slack enough to stay, despite it being aimed squarely at the corporate market for employees to collaborate. (and this is way O/T for this thread and this channel but I'm happy to take this part of the discussion over to #C0CB40N8K if you want to follow-up on it)

2
skylize05:02:50

On desktop/browser, Slack has "Completed" as the first button on hover of any message. But seems to do nothing more than add a emoji Reaction whichever message was hovered.

seancorfield06:02:25

@U90R0EPHA That's just default react-emojis -- and it adjusts the list depending on what you most commonly respond to messages with. For me it's:

skylize20:02:37

> That's just default react-emojis > Yeah. I said that. I was lamenting the fact it is such a useless proxy for feature you crave. > and it adjusts the list depending on what you most commonly > 🙀 I want that! Seems broken on my account. The bright green check box, that I never use, is always first.

seancorfield21:02:07

@U90R0EPHA It's a preference and off by default I believe:

🙏 2
the-alchemist16:02:06

can someone help me understand the relationship between reducers (https://clojure.org/reference/reducers) and transducers (https://clojure.org/reference/transducers)? I came across transducers before reducers , not sure why. the examples on those pages seem similar, and they seem to have similar uses? but they might just be my naivete

the-alchemist16:02:03

great thread, thank you @U01RL1YV4P7

the-alchemist16:02:27

i guess in theory they can be used together, but they seem to be used that way

ghadi22:02:47

Transducers are a decoupling of reducers, and totally subsume them

ghadi22:02:25

pretty much all use of reducers can be replaced by transducers