Fork me on GitHub

Hi, is there a way to extract a function, which already has many references to it, to another namespace using Spacemacs or InterlliJ/cursive? I’m trying to find something in the cljr-refactor package in spacemacs but I can’t find anything.

Drew Verlee03:02:14

There is no limit to how many times a function can be required. Are you asking if there is a way for a editor function to add the require in some context?

Drew Verlee03:02:35

Several tools, lsp and cljr refactor, can do that.


I was trying to move a function to another namespace and wanted to know if lsp or cljr-refactor could do it. It happens that there is no way to do that yet.


in a cljs ns I required [ :refer [read-string]] but I meant to do [cljs.reader :refer [read-string]] (without the tools part, not sure what the difference is) but I'm getting a repl error that read-string is now already used by the tools.reader invocation. How do I switch that out without restarting my repl?


I believe that might be clojure only, not cljs


Oh... Another difference between the dialects... one day I will learn cljs and share these frustrations I suspect...


Hmm, so none of the reified namespace stuff exists in cljs? *ns* produces nil in the REPL...


Yeah, I believe the cljs api for ns docs are here:


Ah, yeah, unmap is actually what you want there. Sorry.


unalias would remove the :as part. unmap removes the :refer'd part.


Unfortunately, it didn't seem to work for me. (ns-unmap ' 'read-string) returns true but then I get the same error when trying to require [cljs.reader :refer [read-string]


No biggie, I'll just restart


You need to unmap it from the calling namespace, not from


:refer creates a mapping into your ns, which you can unmap.


I tried that but then (ns-unmap ' 'read-string) gives me a weird Use of undeclared Var error. Not sure where that last frontend part is coming from.


Mind you, this seems strange to me:

(! 519)-> clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"}}}' -M -m cljs.main -r
ClojureScript 1.11.4
cljs.user=> (require '[ :refer [read-string]])
cljs.user=> (require '[cljs.reader :refer [read-string]])
Why doesn't that second require fail?


You may have more luck getting better cljs answers in #clojurescript


yep, I appreciate ya trying.


(for Clojure there's a in a Contrib lib for Clojure, there is no clojure.reader, and read-string is already in clojure.core so it isn't even comparable)

Chase19:02:47 doesn't seem to be too different. I'm just following along in an older book maybe and let myself get taken down the rabbit hole

John Bradens21:02:29

Is there somewhere I can see how clojure.core functions are defined? Like if I want to see how remove works, or something like that, can I look that up somewhere? I'm doing some exercises where I write my own functions, and I'd love to compare to the originals


In a REPL, you can type (source remove)


You can also git clone , then look in the source file core.clj (or any other source file)


If using to search for clojure.core function documentation, there is also a source code link that takes you directly to the source code of that function definition on GitHub

👍 1

is there an equivalent of the wrap-reload middleware from Ring available in pedestal ?


(just asked in the pedestal channel #pedestal)

Neil Barrett23:02:58

Hi everyone - this is my first time here. Where can I post a code snippet to get help?


You're in the right place here in the #beginners channel

Neil Barrett23:02:33

Ok, here goes ...

(def a1 (atom nil))
(def a2 (atom nil))
(def a3 (atom nil))

(defn putp [c val]
  (let [p (promise)]
    (put! c val (fn [] (deliver p val) ))
    (println "realized?" (realized? p))
    (println "OK")  ))

(def c (chan))

  (reset! a1 "about to put and block until take")
  (putp c 10)
  (reset! a2 "put succeeded"))

(take! c (fn [v] (reset! a3 v)))

(println "@a1:" @a1)
(println "@a2:" @a2)
(println "@a3:" @a3)
Why does @a2 return nil?


FYI for next time - you can use ` on a line before and after a big block of text to quote it as a single block. It’s called a ‘code block’ - there’s also an icon in the editing toolbar for it on the far right.


the callback from put! takes a single argument


should be something like:

(defn putp [c val]
  (let [p (promise)]
    (put! c val (fn [_] (deliver p val) ))
    (println "realized?" (realized? p))
    (println "OK")  ))


when running your code, I saw:

Exception in thread "async-dispatch-1" clojure.lang.ArityException: Wrong number of args (1) passed to: example/putp/fn--15434
Did you see that error?

Neil Barrett00:02:50

Thanks a lot, Adrian - I wrote some comments in #beginners


I'm using emacs+cider. I'm less familiar with your editor, but it should show an error if there was one


the presentation talk you reference is using an alpha version of core.async from 2013, so I'm not that surprised that there's a slight difference

Neil Barrett00:02:51

Sure - I'm just happy to find a solution


async=> (def a1 (atom nil))
async=> (def a2 (atom nil))
async=> (def a3 (atom nil))
async=> (defn putp [c val]
          (let [p (promise)]
            (put! c val (fn [_] (deliver p val) ))
            (println "realized?" (realized? p))
            (println "OK")  ))
async=> (def c (chan))
async=> (future
          (reset! a1 "about to put and block until take")
          (putp c 10)
          (reset! a2 "put succeeded"))
realized? false
        {:status :pending, :val nil}]
async=> (take! c (fn [v] (reset! a3 v)))
async=> (println "@a1:" @a1)
@a1: about to put and block until take
async=> (println "@a2:" @a2)
@a2: put succeeded
async=> (println "@a3:" @a3)
@a3: 10
This works for me


note that it cannot print “OK” until you take! from the channel c since you are using an unbuffered channel


also, i modified the function on the put! call to take a single (ignored) argument


and if i leave that function not taking an argument i can recreate your issue. But I see the following: > Exception in thread “async-dispatch-6” clojure.lang.ArityException: Wrong number of args (1) passed to: metabase.test.util.async/putp/fn--114165


The reason is probably that you are running the code as a "script" in one go, which terminates before the future ran. You can deref the future for that not to happen I think. As you can see @U11BV7MTK ran the code in a repl, step by step, in a process that keeps running.


When running as a main file i get the same behavior: it works when the callback function takes a parameter and errors when that argument is left out

👍 1
Neil Barrett07:02:49

Thanks dpsutton!

Neil Barrett23:02:48

Also, "OK" is not printed.