This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-24
Channels
- # babashka (6)
- # beginners (11)
- # calva (4)
- # clojure (12)
- # clojure-madison (2)
- # clojure-norway (25)
- # clojure-spec (8)
- # clojure-sweden (1)
- # clojurescript (17)
- # datalevin (1)
- # datomic (8)
- # events (5)
- # ghostwheel (1)
- # hyperfiddle (16)
- # off-topic (16)
- # pedestal (1)
- # reagent (6)
- # reitit (1)
- # releases (3)
- # scittle (1)
- # shadow-cljs (5)
- # specter (2)
- # squint (4)
Question: How can I make the symbols from user.clj accessible in every Clojure namespace?
We do it this way:
In user.clj
we have:
(load "monkey_patch_clojure_core")
Then in monkey-patch-clojure-core
we have (amongst other things) this
(ns monkey-patch-clojure-core
(:require
[taoensso.timbre :as log]))
(log/info "Monkey patching clojure.core, adding:")
(log/info (str " " 'pbcopy))
(log/info (str " " 'pbcopy-pr))
(ns clojure.core)
(defmacro pbcopy
"OSX Super convenience: The result of form will be in the OSX paste buffer.
Assumes string."
[& body]
`(clojure.java.shell/sh "pbcopy" :in ~@body))
(defmacro pbcopy-pr
"OSX Super convenience: The result of form will be in the OSX paste buffer, after pr-str
A cleverer thing can happen here: `:in` could be `*out*`. Later."
[& body]
`(clojure.java.shell/sh "pbcopy" :in (pr-str ~@body)))
This is our current monkey patches, and would love comments on it: https://gist.github.com/danieroux/dfb277f47b74fc61c87a92d47edd8c5a
@U9E8C7QRJ I’m too much of a beginner to comment on your monkey patches, but I’m glad I found it and will shamelessly steal it if that’s okay 🙂
I'm trying to figure out how to "kill" a remote-prepl
loop that I want to "manage" the input of in my own code rather than using *in*
.
My example [edit: code in 🧵] is slightly modified from https://github.com/Olical/how-to-be-a-repl-sorcerer/blob/b6bd530f3d0c6b165248d980d7ce6cd28e8da51f/src/sorcery/main.clj#L20. It basically sends a command to a remote prepl and returns the first value the out-fn
receives.
My thinking is that if I have code that want's to run eval once on a remote-prepl, I want to make sure it doesn't just keep spawning threads each time. My expectation is that closing the reader
should stop the remote prepl process.
How can I kill a remote prepl like this? Should I not care that I'm spawning endless new remote-prepl threads?
(I have a hunch this is related to https://clojure.atlassian.net/browse/CLJ-2509 but I'm not positive)
How can I get "DONE" to print?
(ns prepl
(:require [clojure.core.server :as server])
(:import [java.io PipedReader PipedWriter]))
(def srv
(server/start-server {:accept 'clojure.core.server/io-prepl
:port 0
:name "srv"}))
(defn remote-eval [code]
(with-open [reader (PipedReader.)
writer (PipedWriter.)]
(.connect reader writer)
(let [result! (promise)]
(future
(server/remote-prepl
"localhost" (.getLocalPort srv)
reader
(fn [msg]
(deliver result! msg)))
(println "DONE"))
(.write writer code)
(.flush writer)
@result!
;; doesn't print "DONE"
(let [r @result!]
(.close reader)
(.close writer)
;;(.write writer ":repl/quit\n") ;; also tried this
;;(.flush writer)
r))))
(remote-eval "(+ 1 2 3)")