Fork me on GitHub
#off-topic
<
2019-08-28
>
David Pham00:08:47

I am coding in CLJS because my employer wanted to build web apps, and I m convinced them to let me have fun with it xD.

David Pham00:08:38

Now, I slowly convincing other developers to move to clojure, but the task is hard in the data science field

David Pham00:08:57

The ease of R and python is hard to let go.

andy.fingerhut00:08:34

There are folks working on better interaction between Clojure/Java and data science type libs in Python, having fairly regular meetings and publishing the recordings of them. They are in the data-science channel on Slack, and on Clojurians ZulipChat.

nori02:08:23

if i do this can i join #atom

nori02:08:37

fk. #data-science

nori02:08:18

Has anybody got these ridiculous CTRL-, keybindings to work on atom? how?

nori02:08:20

I just spent like ninety minutes breaking my neck over keybindings.

seancorfield02:08:55

@norilinoriginal Are you looking for the #chlorine channel?

seancorfield02:08:23

As for the ctl-, key bindings -- they work fine for me on both Windows and macOS. I haven't tried Linux.

seancorfield02:08:38

This is my Atom/Chlorine setup https://github.com/seancorfield/atom-chlorine-setup that I use on Windows/macOS.

sogaiu05:08:03

@norilinoriginal keybindings in atom are not good to put it mildly. ctrl-, in atom may lead to the settings panel / tab in *nix / windows -- you might find the following to be helpful: https://atom.io/packages/keymap-control: > After Atom starts, Keymap Control looks inside your keymap.cson file for any keybindings that conflict with keybindings from other packages and automatically unbinds them, removing the conflicts which can prevent your new keybindings from working. > This can remove keybindings from Atom's core just as easily as from 3rd party packages. Any keybindings you set in your keymap.cson file will always take precedence, so you can concentrate on setting the keybindings you want, instead of why they don't work.

borkdude11:08:57

in Java/Clojure when writing to stdout in a command line tool, e.g. print "hello" in a loop forever, how you can you stop doing that, when the next program stops consuming input, e.g. with head -n3?

borkdude11:08:24

concrete use case: https://twitter.com/borkdude/status/1166664789323657216 right now this example doesn't halt

borkdude11:08:40

don't know if that's possible

manutter5111:08:41

My understanding of Unix architecture is that the pipe operator is basically a file abstraction. As far as your Clojure program is concerned, it’s just writing to a file, and neither knows nor cares whether that file is ever being read. So I wouldn’t think it was possible for your program to know when to stop. (Also I think you can theoretically feed an infinite number of lines to head — it may stop printing after the first n lines, but I don’t think that stops it from reading and discarding every line after that.)

manutter5111:08:31

That said, you might be able to wrap your command line in a sub-process, and have a consumer function that sent its parent process a kill signal after a certain number of lines of input.

borkdude11:08:37

this program terminates immediately:

yes | head -n3
y
y
y

manutter5111:08:43

$ (bb -o '(defn yes [] (repeat (or (first *command-line-args*) "y"))) (yes)' hello | print-and-die -n 3)

borkdude11:08:40

well, I don't want a special substitute command for reading a number of lines, head should just work, since that's standard bash 🙂

manutter5111:08:15

Yeah, it’s also possible that there’s depths of bash I’ve never plumbed

borkdude11:08:42

I wonder how bash itself does this

borkdude11:08:26

maybe there's a signal being sent around to the other process?

manutter5111:08:58

Substitute head.c for yes.c and you can see the source for head too

borkdude11:08:47

nice, I'll start digging

manutter5111:08:45

Ah, now that’s interesting.

manutter5111:08:24

I’ve seen references to SIGPIPE before but I never really knew what it did.

borkdude12:08:20

@manutter51

(import 'sun.misc.Signal)
(import 'sun.misc.SignalHandler)

(def sig (Signal. "PIPE"))
(def handler
  (reify SignalHandler
    (handle [this signal]
      (println "SIGNAL" signal)
      (System/exit 0))))

(Signal/handle sig handler)

(loop []
  (Thread/sleep 100)
  (println "hello")
  (recur))
$ clj /tmp/sigpipe.clj | head -n3
hello
hello
hello

manutter5112:08:55

Love it 😄

borkdude12:08:54

yeah, it seems to work, but I don't see SIGNAL printed 😉

borkdude12:08:25

(import 'sun.misc.Signal)
(import 'sun.misc.SignalHandler)

(def signal-state (atom nil))
(def sig (Signal. "PIPE"))
(def handler
  (reify SignalHandler
    (handle [this signal]
      (reset! signal-state :PIPE))))

(Signal/handle sig handler)

(try
  (loop []
    (Thread/sleep 100)
    (println "hello")
    (if (= :PIPE @signal-state)
      (System/exit 13)
      (recur))))
It doesn't see the correct exit code, but otherwise it works.

manutter5112:08:18

Try printing to STDERR in your handler fn

borkdude12:08:18

$ clojure /tmp/sigpipe.clj | head -n3
hello
hello
hello
PIPE receivedPIPE received

PIPE received
PIPE received

borkdude12:08:59

added this:

(binding [*out* *err*]
        (println "PIPE received"))

manutter5112:08:43

Surprising it would get called 4 times

manutter5112:08:57

well, depending where you put it

borkdude12:08:32

I read somewhere you might get more than one signal, but at least once is good enough for me

Chase15:08:11

Clojure is in the top 10 for available packages which I find quite respectable for its "niche" status. Then if you add in the access to JVM and JS (the top 2 on the list), Clojure basically has the largest ecosystem in the whole universe, right?! Disclaimer: I have no clue about the accuracy of the methods here, but that can be said about everything these days.

gklijs13:08:39

It seems to be mostly because a lack of central repository in a lot of languages. Swift is a lot newer, but already twice the packages of Clojure, not sure why. And Rust is just behind Clojure but somewhat newer.

Alex Miller (Clojure team)16:08:51

well if clojure has access to java repositories, and clojurescript has access to javascript repositories, seems like you can add all those together :)

dominicm16:08:02

Don't forget NuGet!

Chase16:08:07

I think these numbers are a good counter argument to both the "eww, I don't want to have to know JS or Java to use Clojure" concerns (not that I agree necessarily), well Clojure has over 20,000 of it's own libraries now, you don't have to, and then in reverse too, "Clojure is a small community", well we actually have the largest ecosystem in software development.