Fork me on GitHub
#clojure
<
2020-10-17
>
jmckitrick11:10:41

I’m asking an emacs question here out of desperation. I’ve used paredit-slurp for years, and it always added an extra space between the 2 items. Not anymore. Now, after slurping, I have to add the space between the items on either side of the point. Any ideas how that can be change? This is a feature obviously used all the time in Clojure mode, and it has become a huge annoyance.

octahedrion11:10:48

if Clojure has gen-interface& gen-class and Java source files are merely an intermediate step to bytecode, which Clojure can generate anyway, why do some Clojure projects include Java source files ? Why not generate that bytecode from Clojure ?

p-himik11:10:31

Because it would be harder.

p-himik11:10:03

Not that much harder if you just read a Java source file and compile it from Clojure. But I guess that's not what you meant.

emccue12:10:05

Also because gen-class only works with AOT compilation for some weird reason, and not at the REPL

emccue12:10:14

which is obtuse enough that "just" writing java feels preferable

emccue12:10:12

since otherwise you need to keep track of the load order of your namespaces - its alot less mentally taxing to say "compile java" all in one step

markbastian14:10:27

If you want your interface to preserve generic typing then use a Java interface.

octahedrion14:10:48

@U0JUR9FPH yes the only reasons I could think of were generics and declaring exceptions thrown, both of which could be added to Clojure's ASM bytecode-generation functions

andy.fingerhut14:10:50

By design Clojure’s gen-class and gen-interface do not have the ability create classes/interfaces with all of the options that the Java compiler can. Java is Clojure’s in-line assembler

andy.fingerhut14:10:10

As in, I believe when this question has arisen before, the Clojure core developers have expressed 0 interest in extending the Clojure compiler to include all possible options there

andy.fingerhut14:10:43

At least partly because the Java compiler is right there

octahedrion14:10:50

but say someone else wrote a library providing those features, I think that would be a good thing

octahedrion14:10:04

because I don't like writing Java

andy.fingerhut14:10:40

There might be such a library already, even. I haven’t used one, but there are a lot of libraries out there

andy.fingerhut14:10:54

For interfaces, the Java code is pretty short

andy.fingerhut14:10:59

That library might do it - I have not looked into its capabilities in any detail

Nico14:10:12

hi, I have a data structure like this: [{:title "thing" :content "test" :tags [:tag1 :tag2]}, {:title "thing 2" :content "foo" :tags [:tag1] (this isn't the real data, but it is the real structure) and I'd like one like this {:tag1 [{:title "thing" :content "test"},{:title "thing 2" :content "foo"}] :tag2 [{:title "thing" :content "test"}]} . how would I do this in clojure? (context: I have a list of pages for a website and I want a list for each tag of which pages have that tag)

seancorfield15:10:15

@nihilazo Depending on how fussed you are about extra tags in the rearranged data:

user=> (def pages [{:title "thing" :content "test" :tags [:tag1 :tag2]}, {:title "thing 2" :content "foo" :tags [:tag1]}])
#'user/pages
user=> (group-by :tag (for [page pages tag (:tags page)] (assoc page :tag tag)))
{:tag1 [{:title "thing", :content "test", :tags [:tag1 :tag2], :tag :tag1} {:title "thing 2", :content "foo", :tags [:tag1], :tag :tag1}], :tag2 [{:title "thing", :content "test", :tags [:tag1 :tag2], :tag :tag2}]}
user=> 

seancorfield15:10:02

If you really don't want :tags or :tag in the results, you'll need to do a bit of cleanup.

seancorfield15:10:03

Using (-> page (assoc :tag tag) (dissoc :tags)) instead of (assoc page :tag tag) gets you part of the way. Removing the :tag from each page after you've grouped them is a bit more work.

Nico15:10:35

ah, thanks! I did not know group-by exists, that is a very useful function!

cpmcdaniel17:10:20

Is nrepl still the way to go if I want to embed a socket REPL in my application, or does Clojure 1.10 have this ability built-in now?

andy.fingerhut17:10:07

In most usage I have seen "socket REPL" is a distinct thing from "nrepl". socket REPL functionality is built into Clojure itself, as you have found a link for. Such a socket REPL does not use the nrepl 'wire format' for messages. (Perhaps it might be possible to make it do so -- I am not sure, but if so, the code for doing so is not built into Clojure core itself, which contains no nrepl-specific code)

andy.fingerhut17:10:36

Many people prefer to avoid nrepl. nrepl is used very often for connecting a REPL from Emacs to a running Clojure program, and I am sure there are other editors besides Emacs for which people have implemented the nrepl protocol between that editor and a running Clojure program. Emacs and most (all?) editors also support socket REPL connections.

borkdude18:10:12

> Many people prefer to avoid nrepl. People avoiding nREPL might be louder about it than those just using it (probably a far huger number)

seancorfield18:10:05

Indeed, even as one of those people, I very much doubt that we are "many" 🙂

andy.fingerhut18:10:24

Sorry, not trying to give the wrong impression here. I do not know of any survey results on fraction of Clojure devs who use/avoid nrepl.

borkdude18:10:36

Given the distribution of editors in last year's survey, that could give some hint

andy.fingerhut18:10:01

Agreed that the vast majority of Emacs Cider users are humming along using nrepl, whether they know it or not.

seancorfield18:10:39

At least some of the 43% Emacs crowd use inferior mode I guess, and the 5% Atom users are nearly all Socket REPL users (although Chlorine does support nREPL now and maybe a few of them are still struggling along with ProtoREPL?).

borkdude18:10:07

Maybe a nice question for next year's survey? #clojure-survey

andy.fingerhut20:10:39

Eh, I suspect whether someone uses nrepl is often and "under the hood" detail for them, and probably not of much interest to any but a very few tool developers.

seancorfield18:10:12

@cpmcdaniel The Socket Server was added in Clojure 1.8. It's a bare REPL so you cannot connect an nREPL client to it.

borkdude18:10:36

There is also prepl - anyone using that?

simon18:10:29

I've got a file that requires all other files and calls the function run-all-tests. Currently, in Calva, I can execute that file by pressing CTRL+`ENTER` and in Intellij/Cursive I usually open the file and hit SHIFT+`CMD`+`L` to load the file in the REPL to execute the tests. What bothers me is that in either way I leave the current file and it involves multiple steps. Do you know a better way of doing this or how to set a shortcut in either Calva or Intellij/Cursive that executes all tests?

seancorfield18:10:36

I think Conjure uses that (prepl).

seancorfield18:10:59

@simon.zachau No idea how to do it in Calva or Cursive, but I'm pretty sure CIDER supports that in Emacs and I know Chlorine supports it in Atom (since I use that).

simon18:10:10

@seancorfield thanks! I think there must be a way in Intellij/Cursive because I used it a few years ago, but I don't remember it 🙈

andy.fingerhut18:10:32

The #cursive channel is a good place to ask, if no one responds in this channel

👍 3
seancorfield18:10:24

If you can bind hot keys to arbitrary code execution, you can do it -- that's how I customize stuff in Atom (so I have a hot key that runs tests in the test ns associated with the src file that I'm currently in, for example: so when I'm editing foo.bar, I can hit ctl-; X and it requires foo.bar-test or foo.bar-expectations and then runs the tests in whichever require was successful).

👍 3
mauricio.szabo18:10:49

I think Conjure is moving away from prepl

dharrigan18:10:16

It has. It's now uses nrepl

mauricio.szabo19:10:42

@borkdude I believe nrepl, as @dharrigan said :)