Fork me on GitHub
#clojure
<
2018-08-05
>
ghadi00:08:51

Whatcha doing with Signal? @lilactown

puzzler00:08:16

I've been using arrays a lot this past week, and was reminded how easy it is to shoot yourself in the foot performance-wise in Clojure when working with arrays. Make sure to always type hint your calls to aget, or your performance will plummet and you won't get any warnings to help. So be careful. To avoid these problems, I try to use core.matrix :vectorz implementation for multi-dimensional arrays of doubles, hiphip makes it more pleasant to work with primitive 1d arrays. I haven't found any decent option for multi-dimensional arrays of things other than doubles.

12
jaihindhreddy-duplicate07:08:51

https://www.youtube.com/watch?v=iQwQXVM6oiY This made me understand what a tower of abstractions the clojure world is.

lilactown00:08:40

@ghadi they changed the way the desktop client looks yesterday and I hate it, so I decided to try and write my own 😝

ghadi00:08:13

Sounds fun! Clojure + Clojurescript or Clojure + some jvm GUI?

lilactown00:08:35

I was gonna see about setting up a Clojure client first and then maybe play with a swing GUI

benzap02:08:44

Have you checked out JavaFX? I think it's supposed to be easier than swing.

lilactown02:08:31

everyone I’ve heard try and use JavaFX in Clojure has not enjoyed it

lilactown02:08:42

seesaw on the other hand seems like a pretty well thought out lib

benzap06:08:14

Yeah, seems like JavaFX doesn't have a clojure wrapper yet, or at least one that is considered mature

lilactown00:08:40

Honestly what I'd like is an Emacs buffer I could use to interact with it, but my elisp-fu is quite weak. So I don't know whether swing or Emacs is more unrealistic lol

lilactown01:08:05

I've also found that the underlying signal libs are a real PITA. So I'm going to use signal-cli, either the dbus interface or see if I can use it as a library

thiru01:08:39

With the new nrepl is it possible to launch a repl and connect to an existing nrepl server?

thiru01:08:49

.. using CLI tools

thiru01:08:14

Something like clj -Sdeps '{:deps {nrepl {:mvn/version "0.4.4"}}}' -m nrepl.cmdline --port 7888 --interactive

thiru01:08:31

But which doesn't start a new nrepl server, but connects to an existing one

seancorfield01:08:25

@thiru0130 It's considered a bit rude to @ someone who isn't already active in the channel right now. It's the middle of the night for Bozhidar.

seancorfield01:08:27

It's Saturday evening (here on the West Coast of America) so there's probably not going to be many people around to answer your question for a while.

thiru01:08:50

Ahh yes sorry bozhidar!

thiru01:08:15

thanks sean I'll remember this.. only a few days new to slack as well

seancorfield01:08:17

With clj you can only run one set of "main options" so you can run either a -main function in a namespace or evaluate an expression. You can't run both.

pauld01:08:23

Thanks @seancorfield. I've @ 'd people several times without knowing this.

seancorfield01:08:16

If you look at my .clojure/deps.edn file, you'll see that starting an nREPL server can be done via the -e main option...

lilactown01:08:43

I think @thiru0130 wants just a client

seancorfield01:08:38

Ah, I read "launch a repl and connect to an existing nrepl server" to mean "and also"...

seancorfield01:08:32

I wonder if you can construct a suitable -e option to start an interactive client?

thiru01:08:50

thanks @seancorfield.. I'll have to take a closer look at the code I suppose..

seancorfield01:08:57

Looks like the run-repl function in that namespace is private...

thiru01:08:00

I love clojure/lisp but the tooling is just still very frustrating.. 😕

thiru01:08:03

I suppose that has something to do with wanting to use all my favourite tools.. vim, rebel-readline, etc.

seancorfield01:08:42

OK, so the answer is "yes, you can connect to an existing nREPL server via the client in nrepl/nrepl"... here's what I did:

seanc@DESKTOP-JMD1DBJ:~$ clj -Sdeps '{:deps {nrepl {:mvn/version "RELEASE"}}}' -e "(require,'[nrepl.cmdline,:as,c]),(#'c/run-repl,\"localhost\",7888)"
nREPL 0.4.4
Clojure 1.9.0
OpenJDK 64-Bit Server VM 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11
user=>
and that connected to an existing nREPL server running on port 7888 (which I had started in another window).

seancorfield01:08:32

Note the escaped \" around the hostname (localhost in this case) and the commas , used instead of spaces (to pass through the shell script correctly).

seancorfield01:08:05

It's relying on calling a private method nrepl.cmdline/run-repl so it is not part of a public API.

seancorfield01:08:50

Here's the full example... in one window:

seanc@DESKTOP-JMD1DBJ:~/clojure$ clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "RELEASE"} nrepl {:mvn/version "R
ELEASE"}}}' -m nrepl.cmdline --port 7888
nREPL server started on port 7888 on host 0:0:0:0:0:0:0:0 - nrepl://0:0:0:0:0:0:0:0:7888
this selects Clojure 1.10.0-alpha6; and in another window
seanc@DESKTOP-JMD1DBJ:~$ clj -Sdeps '{:deps {nrepl {:mvn/version "RELEASE"}}}' -e "(require,'[nrepl.cmdline,:as,c]),(#'c/run-repl,\"localhost\",7888)"
nREPL 0.4.4
Clojure 1.9.0
OpenJDK 64-Bit Server VM 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11
user=> (clojure-version)
"1.10.0-alpha6"
user=>
so we can see the REPL client itself is running Clojure 1.9.0 but the code is run in the 1.10.0-alpha6 REPL started in the other window.

seancorfield01:08:18

@thiru0130 Is that what you're looking for?

thiru01:08:58

Awesome thank you @seancorfield!!

thiru01:08:04

Yes this is exactly what I wanted

kingcode02:08:43

How does one get around basic floating-point inaccuracies like (+ 10.2 0.1) => 10.29999999…

kingcode02:08:54

I am trying to get (10.1, 10.2, 10.3 ….) from (range 10.0 11.0 0.1), but get => (10.0 10.1 10.2 10.299999999999999 10.399999999999999 10.499999999999998 10.599999999999998 10.699999999999998 10.799999999999997 10.899999999999997 10.999999999999996)

llsouder02:08:28

use discrete values

llsouder02:08:49

(+ 101 102 103) ;;tenths

kingcode02:08:41

@Ilsouder thank you!

kingcode02:08:16

I guess floating-point arithmetic is a big stay-away-from..

andy.fingerhut02:08:24

Yes, restricting yourself to arithmetic on integers or ratios is exact.

andy.fingerhut02:08:05

Java also has a BigDecimal class that I believe does exact arithmetic for plus and minus, at least, although cannot of course for division.

kingcode02:08:35

ok thanks Andy/Ilsouder - (+ (bigdec 10.1) 0.1) is still inacurrate for me

sundarj03:08:26

as Andy mentioned, you can also use ratios:

=> (+ 102/10 1/10)
103/10
=> (range 10 11 1/10)
(10 101/10 51/5 103/10 52/5 21/2 53/5 107/10 54/5 109/10)

kingcode02:08:22

There is something that feels really wrong with getting 10.29999999 out of trying to add a single precision number though…

kingcode02:08:46

It’s not a case of asking too much precision..

andy.fingerhut02:08:09

If you want accurate answers for bigdec, all arguments must be bigdec. Mixing arithmetic with floating point and bigdec gives approximate floating point results.

andy.fingerhut02:08:15

@kingcode IEEE floating point numbers store mantissa as binary number. 1/10 in decimal is easily represented exactly as 0.1, but in binary cannot be represented exactly with a finite number of digits. It is like trying to write 1/3 exactly in decimal -- you cannot.

kingcode02:08:00

@andy.fingerhut aw ok…I thought the larger type was infecting less precise ones, but I tried (->> (map bigdec [10 11 0.1]) (apply range)) and that worked as expected.

andy.fingerhut02:08:29

You can also write bigdec constants in Clojure by appending M to the number, e.g. (+ 0.1M 0.2M)

kingcode02:08:19

Nice explanation of the binary mantissa - didn’t know that.

bozhidar06:08:24

@thiru0130 You can also file a ticket about this and we can make it easier to connect to a running server with the built-in client. Generally the only reason why it’s not currently existing is that my assumption was that few people were using it, as it’s kind of basic compared to something like REPL-y.

arnaud_bos13:08:34

What was the idea behind sync's "transaction-flags"? Found in the docstring: "transaction-flags => TBD, pass nil for now"

thiru16:08:40

Thanks @bozhidar. The main reason I wanted this was to try and use it in conjunction with rebel-readline. Rebel doesn't work with REPL-y I guess because REPL-y needs control over manipulating the readline, just like rebel. So I thought that if I avoided REPL-y and leiningen I could use rebel. But this is not possible. I talked to Bruce and he said it won't be possible to use rebel inside an nREPL session.

skrat16:08:11

Is there a way I can get a ring handler fn from pedestal service-map?

thiru16:08:53

So in summary I'm not going to make use of this afterall. I guess I'll still file a ticket though as it may be useful for some people? Also it seems good to have the API symmetric in this manner. I.e. we can start an nREPL server at the command-line, so we should also be able to connect to an existing one?

bozhidar19:08:38

@thiru0130 Yeah, certainly. I was thinking of adding some --connect flag anyways.

👍 4