Fork me on GitHub

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


I have a Clojure repl. I want to open up a port on 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]


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.


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


Maybe ask in #cursive then.


I'm not using cursive.


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


Cursive is a plugin for IntelliJ for writing Clojure code.


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


I know what Cursive is, yes.


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


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


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


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


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.


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...


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.


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.


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


Yes, was just testing it.


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


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


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


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


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


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


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


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" ?


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


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


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


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


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


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


Have you thought of using reify instead?


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


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


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


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


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


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).


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?


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.


algorithms.logic=> (defn ^long foo [^long i] (mod i 10))
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?


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


FYI Eastwood would warn about that type hint being incorrect.