Fork me on GitHub
#clojure
<
2018-11-24
>
todo03:11:36

in boot, how do I add a repo that is not maven ?

todo04:11:09

I have a Clojure repl. I want to open up a port on 127.0.0.1 where only locally running programs can connect, and they can submit arbitrary sexps to be evaluated (I'm the only user on the local machine). What is the right lib for this? [The user case is that I have a rust program that wants to send commands to the Clojure repl]

seancorfield04:11:24

You probably want a simple Socket REPL Server. You can do that just by starting your Clojure process with JVM options that specify the socket REPL port.

todo04:11:58

Hmm, this is a bit messier. My "Clojure repl" is started via IntelliJ IDEA IDE Scripting Console via clojure-jsr223

seancorfield04:11:28

Maybe ask in #cursive then.

todo04:11:57

I'm not using cursive.

seancorfield04:11:31

Then I don't understand what you're saying. IntelliJ is a development environment.

todo04:11:20

Cursive is a plugin for IntelliJ for writing Clojure code.

todo04:11:42

There is something in IntelliJ called "IDE Scripting Console" which allows you to use Groovy/JS to script IntelliJ itself.

seancorfield04:11:48

I know what Cursive is, yes.

todo04:11:54

With some hackery, you can use Clojure to script IntelliJ.

todo04:11:12

My point is "using IntelliJ IDEA Scripting Console + Clojure" is orthagonal to Cursive.

todo04:11:22

You seemed to hold the belief that "IntelliJ + Clojure" implied using Cursive.

seancorfield04:11:54

I answered your original question about having a way for Rust to talk to Clojure via a REPL.

seancorfield04:11:35

I suggested #cursive because the folks there would likely know enough about IntelliJ to tell you how to specify those JVM options for the process you're starting.

seancorfield04:11:17

If you can't provide JVM options for the process you're starting, then you'll have to start the Socket REPL manually I think...

todo04:11:09

Yeah, that's what I'm currently googling. "socket repl" seems precisely what I want, the question now is how to start it from inside a clojure repl.

seancorfield04:11:35

I'm trying to find the docs on starting the Socket REPL manually. I've just never needed to do it -- I just provide the JVM options insted.

seancorfield04:11:47

Ah, here we go... clojure.core.server...

todo04:11:51

Yes, was just testing it.

todo04:11:56

(clojure.core.server/start-server
 { :port 4001
   :name "my socket repl"
   :accept 'clojure.core.server/repl
   } )
appears to work.

todo04:11:04

(I can telnet to localhost 4001, and get a repl).

todo04:11:23

Thanks for your help, the tricky part was figuring out the ":accept" argument -- that part was not very well documented and took some googling.

seancorfield04:11:09

Yeah, I run Socket REPLs on a number of Clojure processes -- but I always have access to start them with the JVM options.

seancorfield04:11:31

I used to start nREPL servers programmatically -- but that's a lot of baggage to carry in your program.

todo04:11:09

so start-server is more generic than just a clojure-socket-repl right? in that because we can specify the :accept function, we get to define whatever read-eval-print loop function we want

seancorfield04:11:54

Right, you can start a prepl server instead if you're using Clojure 1.10.

todo05:11:52

I'm doing "cat cmd.txt | telnet localhost 4001" and getting nothing back. I suspect this is due to telnet closing before getting the result back from the socket repl server (manually telnetting + manually typing the comamnds work). Is there a way to tell telnet to "wait 1 sec for result" ?

seancorfield05:11:39

Try adding a (println "done") at the end of cmd.txt and see if that is printed.

todo05:11:38

cat cmd.txt | telnet localhost 4001 -- gets nothing cat cmd.txt | ncat localhost 4001 -- works fine

seancorfield06:11:37

Good to know @todo -- glad you've found a workaround!

cfleming09:11:22

@todo I’m curious, can you tell us what you’re using it for?

roti09:11:12

can I extend a function object to a java interface? I feel this should be possible with extend, but I don't know what type the function is

roti10:11:00

in other words, can I make a function be usable in places where my java interface is required?

val_waeselynck10:11:19

Have you thought of using reify instead?

roti12:11:07

yes, but I want to see if it would be possible with extend

val_waeselynck12:11:03

I don't think you can extend a class to an interface after the class has been declared. So the answer would be no.

roti13:11:39

isn't this what extend-type does? (make a class extend a protocol after it has been declared)

andy.fingerhut15:11:42

extend-type can extend a protocol, but not a Java interface, I don't think.

andy.fingerhut15:11:11

a Clojure protocol has some things in common with a Java interface, but is not identical to a Java interface.

pez16:11:17

I need help! To keep Calva Formatter reasonably quick I only format the current enclosing form while typing. For this I use paredit.js to expand the selection until it is enclosed in brackets of some kind. The code for this looks like so:

(defn enclosing-range
  "Expands the range from pos up to any enclosing list/vector/map/string"
  [{:keys [all-text idx] :as m}]
  (assoc m :range
         (let [ast (paredit/parse all-text)
               range ((.. paredit -navigator -sexpRange) ast idx)]
           (if (some? range)
             (loop [range range]
               (let [text (apply subs all-text range)]
                 (if (and (some? range)
                          (or (= idx (first range))
                              (= idx (last range))
                              (not (contains? (set "{[(") (first text)))))
                   (let [expanded-range ((.. paredit -navigator -sexpRangeExpansion) ast (first range) (last range))]
                     (if (and (some? expanded-range) (not= expanded-range range))
                       (recur expanded-range)
                       (cljify range)))
                   (cljify range))))
             [idx idx]))))
This works nicely until I feed it something like:
([]
[])
with the cursor (`:idx`) at position 6 (the beginning of the second line). Then my functions finds the text []\n[] which might look enclosed to my function, but actually are just two free floating forms and hard for cljfmt to format correctly. I am pulling my hair to figure out how I can recognize this in a reliable way and keep on expanding until I find those parens (in this case).

lilactown18:11:56

so the gist is you get the whole file (`all-text`) and the current cursor pos (`idx`) and you need to figure out if you’re in closed matching braces/parens?

pez19:11:21

Almost, i need to find the enclosement. But, yes, right now what is lacking is a way to know if I have really found it.

schmee18:11:43

algorithms.logic=> (defn ^long foo [^long i] (mod i 10))
#'algorithms.logic/foo
algorithms.logic=> (foo 55)
Execution error (AbstractMethodError) at algorithms.logic$foo/invokePrim (form-init8039649538611260960.clj:-1).
Method algorithms/logic$foo.invokePrim(J)Ljava/lang/Object; is abstract
ehh… what?

schmee18:11:45

ohh, first type hint is in the wrong position, should be on the args list

andy.fingerhut18:11:28

FYI Eastwood would warn about that type hint being incorrect.