This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-06
Channels
- # beginners (49)
- # calva (12)
- # cider (5)
- # cljdoc (4)
- # clojure (51)
- # clojure-dev (1)
- # clojure-europe (16)
- # clojurescript (56)
- # conjure (2)
- # copenhagen-clojurians (1)
- # core-async (4)
- # data-science (4)
- # docker (1)
- # emacs (4)
- # gratitude (1)
- # malli (2)
- # meander (2)
- # missionary (7)
- # off-topic (21)
- # pedestal (3)
- # polylith (6)
- # shadow-cljs (28)
- # spacemacs (1)
- # sql (9)
- # transit (8)
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.
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?
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 [cljs.tools.reader :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?
ns-unalias
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: https://cljs.github.io/api/cljs.core/#ns
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 'cljs.tools.reader 'read-string)
returns true
but then I get the same error when trying to require [cljs.reader :refer [read-string]
You need to unmap it from the calling namespace, not from cljs.tools.reader.
:refer
creates a mapping into your ns, which you can unmap.
I tried that but then (ns-unmap 'frontend.chat.api 'read-string)
gives me a weird Use of undeclared Var frontend.chat.api/frontend
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 '[cljs.tools.reader :refer [read-string]])
nil
cljs.user=> (require '[cljs.reader :refer [read-string]])
nil
cljs.user=>
Why doesn't that second require
fail?You may have more luck getting better cljs answers in #clojurescript
(for Clojure there's a clojure.tools.reader
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)
https://github.com/clojure/tools.reader/issues/10 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
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)
Cool thanks!
If using https://clojuredocs.org/ 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
is there an equivalent of the wrap-reload
middleware from Ring available in pedestal
?
(just asked in the pedestal channel #pedestal)
Hi everyone - this is my first time here. Where can I post a code snippet to get help?
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))
@p
(println "OK") ))
(def c (chan))
(future
(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))
@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?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
Sure - I'm just happy to find a solution
async=> (def a1 (atom nil))
#'metabase.test.util.async/a1
async=> (def a2 (atom nil))
#'metabase.test.util.async/a2
async=> (def a3 (atom nil))
#'metabase.test.util.async/a3
async=> (defn putp [c val]
(let [p (promise)]
(put! c val (fn [_] (deliver p val) ))
(println "realized?" (realized? p))
@p
(println "OK") ))
#'metabase.test.util.async/putp
async=> (def c (chan))
#'metabase.test.util.async/c
async=> (future
(reset! a1 "about to put and block until take")
(putp c 10)
(reset! a2 "put succeeded"))
realized? false
#object[clojure.core$future_call$reify__8477
"0x14d69935"
{:status :pending, :val nil}]
async=> (take! c (fn [v] (reset! a3 v)))
OK
nil
async=> (println "@a1:" @a1)
@a1: about to put and block until take
nil
async=> (println "@a2:" @a2)
@a2: put succeeded
nil
async=> (println "@a3:" @a3)
@a3: 10
nil
This works for menote that it cannot print “OK” until you take!
from the channel c since you are using an unbuffered channel
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
Thanks dpsutton!
Also, "OK" is not printed.