Fork me on GitHub
Greg Jennings00:01:02

Hi everyone, I’m trying to do a very simple tutorial and I’m not sure why this is giving me a compile error. Sorry for the stupid question

(ns tutorial.core
  (:require [clojure.string :as str])

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (def str1 "This is a string")  
  (str/blank? str1)

Greg Jennings00:01:13

This yields the error: Syntax error compiling at (core.clj:9:3). No such namespace: str

Greg Jennings00:01:02

but this works:

(ns tutorial.core
  (:require [clojure.string :as str]) 

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (def str1 "This is my second string")  
  (clojure.string/blank? str1) 

Greg Jennings00:01:22

sorry for the stupid beginner question


an aside: def inside defn doesn't do what you probably think it does - it creates a new global at namespace scope


it doesn't create a binding that's local to that function


use a let instead (still as part of the aside)


for the error of str namespace not being found, there has to be something else going on, the code is correct aside from the def usage

Greg Jennings00:01:53

so, thanks for that. Interestingly when I tried switching def to let, I got this: (let str1 "This is a string") => Syntax error macroexpanding clojure.core/let as core.clj:7:3).


(let [str1 "This is a string"] (str/blank? str1))


let has explicit scope based on its parens

Greg Jennings00:01:33

is my clojure setup corrupted or something I wonder. I’m using VSCode and Calva on a mac


@greg024 I would assume more likely user error in the IDE, you can verify without any of the tooling by running clj path/to/file.clj in a terminal

Greg Jennings00:01:35

ah sorry - that worked, but the other Unresolved namespace str. Are you missing a require? still persists


that sounds like some reset / error clearing is needed via your IDE UI


I assume there's a channel for Calva / vscode users here

Greg Jennings01:01:55

yep, this indeed does run fine (I’m using lein so I did lein run on the project):

(ns tutorial.core
  (:require [clojure.string :as str]) 

(defn -main
  [& args]
  (println (str/blank? "str1"))

Greg Jennings01:01:14

it must be something with my vscode setup. Thanks!


You likely are try to evaluate the definition of -main without having evaluated the ns declaration above


Exactly. I get this error all the time if I forget to evaluate the ns expression. In Calva, Ctrl + Alt + Enter evaluates the whole file (Windows/Linux).


How do I load/require an in-memory namespace?


@lockdown- Not quite sure what you're asking. If a namespace has been required, it will be in memory. Do you mean "How do I reload a namespace from disk?"


I mean a ns with no file, like after (create-ns 'foo)


Hmm, never seen anyone call create-ns to be honest, but you can just refer to its content via its name...

seancorfield06:01:07 if you have added any Vars to it, you can just say foo/some-var to refer to some-var in that foo namespace.


You can also use alias to add a local alias to an in-memory namespace.



user=> (in-ns 'foo)
#object[clojure.lang.Namespace 0x1bb9aa43 "foo"]
foo=> (clojure.core/refer 'clojure.core)
foo=> (defn bar [n] (* n n ))
foo=> (in-ns 'user)
#object[clojure.lang.Namespace 0x2e52fb3e "user"]
user=> (foo/bar 4)
user=> (alias 'f 'foo)
user=> (f/bar 5)
(you don't need create-ns since in-ns auto-creates it -- but it's "empty" -- it doesn't even have clojure.core stuff in it, so we need to refer in the core functions to make it easier to define stuff in the ns)


there's a special case so that you can always run (refer-clojure) even in a namespace where clojure.core isn't referred oops I need coffee, just tested and this does not actually work in 1.10.1


(! 1096)-> clj
Clojure 1.10.1
user=> (in-ns '
#object[clojure.lang.Namespace 0x17ca8b92 ""]> (clojure.core/refer-clojure)
nil> (defn quux [n] (* n n))
#'> (in-ns 'user)
#object[clojure.lang.Namespace 0x377008df "user"]
user=> ( 4)
user=> (alias 'f '
user=> (f/quux 5)
^ @U051SS2EU?


(since clojure.core isn't referred into the ns, you need to qualify that call to refer-clojure as I did above for the call to refer)


right, clojure.core/refer-clojure alwasy work, as clojure.core is always loaded


but I thought there was a special case for refer-clojure to work


yes, very much thanks, you cleared my confusion


If you use intern you can add things to your namespace created with create-ns, but have names resolved using whatever the current space is


ah, was looking for that, the idea was to create the ns without switching to it, hence create-ns instead of in-ns


Ah, yeah, I forgot about interning into other nses...


user=> (create-ns 'foo)
#object[clojure.lang.Namespace 0x1bb9aa43 "foo"]
user=> (intern 'foo 'bar (fn [n] (* n n )))
user=> (foo/bar 4)
user=> (alias 'f 'foo)
user=> (f/bar 5)
@lockdown- There's a revised REPL session 🙂


Hi everyone, Can anyone help me with this? Why do I keep getting :

Reflection warning, stellar/single_runner/components/state/ref/transition.clj:140:3 - call to method submit on java.util.concurrent.ExecutorService can't be resolved (argument types: unknown).
for this piece of code :
(defn resp-handler
  [state db om
   ^java.util.concurrent.ExecutorService pool
   ^java.util.concurrent.ExecutorService db-pool]
  (async/go-loop []
      (let [cid (otocol/<-client-id om)]
        (when-let [{r-cid :client-id :as resp}
                   (async/<! (otocol/<-resp-ch om))]
          (if (= r-cid cid)
             ^java.util.concurrent.ExecutorService pool
             ^Callable (fn []
                          state db om resp db-pool)))
             ^java.util.concurrent.ExecutorService db-pool
             ^Callable (fn []
                         (opdb/->response db resp))))))
      (catch Exception e
         (ex-info "resp-handler"
                  {:cause e
                   :params {:state state}}))))
Thanks a lot

Alex Miller (Clojure team)14:01:54

those Callable type hints probably aren't getting applied

Alex Miller (Clojure team)14:01:38

but if you pull them up to let locals and then type-hint the local reference, that will work

Alex Miller (Clojure team)14:01:59

(let [handle-resp (fn [] (handle-resp-on-start ...))]
   (.submit pool ^Callable handle-resp))


Sorry, Alex But even after changing it to

(defn resp-handler
  [state db om
   ^java.util.concurrent.ExecutorService pool
   ^java.util.concurrent.ExecutorService db-pool]
  (async/go-loop []
      (let [cid (otocol/<-client-id om)]

        (when-let [{r-cid :client-id :as resp}
                   (async/<! (otocol/<-resp-ch om))]
          (let [resp-handler (fn []
                                state db om resp db-pool))
                stray-resp-handler (fn []
                                     (opdb/->response db resp))]
            (if (= r-cid cid)
              (.submit pool    ^Callable resp-handler)
              (.submit db-pool ^Callable stray-resp-handler)))))
      (catch Exception e
         (ex-info "resp-handler"
                  {:cause e
                   :params {:state state}}))))
I still get the same reflection-warning.


call to method submit on java.util.concurrent.ExecutorService can't be resolved (argument types: unknown).

Alex Miller (Clojure team)19:01:36

are you importing Callable?


No I’m not But there are other cases of .submit in the same ns that do not cause reflection warning

Alex Miller (Clojure team)04:01:39

you have to import java.util.concurrent.Callable - it might not be needed in the other cases


Thanks a lot Alex but that didn't fix it either.

Alex Miller (Clojure team)14:01:22

the hints on pool in the .submit call shouldn't be needed - the hint at the top is sufficient there


Thanks a lot @alexmiller Why weren't the ^Callable type hints getting applied before ? Did it had something to do with fn form or is there sth I don't know ?

Alex Miller (Clojure team)14:01:18

function objects in general don't have metadata

Alex Miller (Clojure team)14:01:39

so that metadata doesn't have anywhere to go


Hello! Is there any way to deprecate a single defmethod of a defmulti?


supposing there was, what benefit would it have? suppose foo is a defmethod that is deprecated. here x may or may not trigger the method that is deprecated (foo x) do you want some indication in your editor that it is deprecated?

thanks 4

I agree this sound weird. Callers of a multimethod shouldn't care about which dispatch branch was hit


if you want feedback in the program, you could tick a metric or emit a log that said "vestigial branch hit, rework the calling code"

thanks 4

Yeah, I think this is the goal. I'm forwarding a question that was asked in my organization. It's a multi dispatcher that returns a token, and a single dispatcher will be removed

Alex Miller (Clojure team)15:01:51

or you can literally remove it


Yeah, but I think the point of deprecation is to give visual hint and time to everybody rework their code without a hard break. But what I'm seeing is that there is no way to do that


But thanks!


(if @filtered [records ^{:key "t"} true] [records ^{:key "f"} false]) i can't make refresh the records element when filtered is changed


Looks like this could be Reagent specific, I'd try asking in #reagent


btw my first attemp was [records @filtered]


this works fine but obviously far from ideal

(if @filtered 
            [:<> {:key "t"} [records true]] 
            [:<> {:key "f"} [records false]] )


@m373h4n I'm unsure what you're trying to achieve here. could you post some expected/desired output from that statement? your first example seems to be trying to add metadata to a boolean which I don't think you can do. your second example is creating a 3 element vector with the first element being the keyword :<> and the second element being a map


(defn showme [tf]
    [rfsubs tf] ;<<<<--- This doesn't change
    (if rfsubs [:p "TRUE"] [:p "FALSE"])))

(defn testi []
  (r/with-let [filtered (r/atom false)]
     [:button {:on-click #(reset! filtered (not @filtered))} "CHANGE"]
     [showme @filtered]]


I made simple sample of my problem


when you click button it should show text TRUE or FALSE but it doesn't


right yes this is a reagent question, I don't know reagent sorry.

🍺 4

can you try it without the with-let bindings? just (defn showme [filtered?] (if filtered? [:p "True"] [:p "False"]))


then it works. but I need with-let in the real function. this was just demonstration of my problem

Eric Ihli21:01:01

const persistNavigationState = async (navState) => {
  try {
    await AsyncStorage.setItem(persistenceKey, JSON.stringify(navState))
  } catch(err) {
    // handle the error according to your needs
const loadNavigationState = async () => {
  const jsonString = await AsyncStorage.getItem(persistenceKey)
  return JSON.parse(jsonString)

const App = () => <AppNavigator persistNavigationState={persistNavigationState} loadNavigationState={loadNavigationState} />;
How is an async function created in ClojureScript? I'm having a hard time finding what happens behind the scenes to know how to create a CLJS version of the persistNavigationState function that will work with ReactNavigation as in that example. (edited)


I believe the most common way to handle this would be to use a promise instead of async/await.

(-> (.setItem AsyncStorage persistenceKey (.stringify JSON navState))
    (.then (fn [resolve reject]

🤙 4

When await-for times out, what happens to the actions it was waiting on? Do they get to live out their natural lives?


await (and await-for) is basically just a ping/pong to an agent. drop an action on their queue of actions to let me know when it is run


not even basically actually, looking at the implementation that is exactly how it is implemented


Looking for ways to replace in the string

[sql column name]
Characters in
#{"[" "]" " "}
to be used as the {:identifiers fn} function in


replace what, with what result?


clojure.string/replace and clojure.string/replace-first can do some kinds of replacements in strings, but not sure from your stated request exactly what you are looking for.


Sorry, trouble formatting in slack. I want to remove a set of characters, this. This will be used as the identifiers cleaning function in opts parameter


So given a string "[sql column name]" you want back a result that is the sequence of strings ("sql" "column" "name") ?


I'm not familiar with the argument of you mention, so I am perhaps not the ideal person to help, but if you can describe the result you are looking for....


I think I can take care of that part. But here's input "[sql column name]" and output "sql_column_name"

Pavel Klavík23:01:02

you can just use clojure.string/replace

Pavel Klavík23:01:55

something like

(-> input (str/replace #"[\[\]]" "") (str/replace " " "_"))


Great! just got through the docs and see replace matchers is a regex

Pavel Klavík23:01:45

ya, it can work with regex, string, characters, quite strong


It can be a regex, but it can also be a character or a string -- whatever you need for the situation at hand.


Thanks! I was hoping use just one call to replace, but couldn't work out the regex. Two is much easier atm.

Pavel Klavík00:01:48

You could even write it like that:

(reduce (fn [input [from to]] (str/replace input from to)) input {"[" "", "]" "", " " "_"})


(defn sql-column [^String s]
  (-> s
    (str/replace " " "_")
    (str/replace #"\[|\]" "")))

(defn sql-column2 [^String s]
  (reduce (fn [s [from to]] (str/replace s from to)) s {"[" "", "]" "", " " "_"}))


;;for fun:
 (criterium/quick-bench (sql-column2 ["sql column x y z"]))
Evaluation count : 89472 in 6 samples of 14912 calls.
             Execution time mean : 4.911902 µs
    Execution time std-deviation : 144.066895 ns
   Execution time lower quantile : 4.743076 µs ( 2.5%)
   Execution time upper quantile : 5.114157 µs (97.5%)
                   Overhead used : 1.686448 ns
=> nil
(criterium/quick-bench (sql-column ["sql column x y z"]))
Evaluation count : 129804 in 6 samples of 21634 calls.
             Execution time mean : 4.812074 µs
    Execution time std-deviation : 613.110069 ns
   Execution time lower quantile : 4.287340 µs ( 2.5%)
   Execution time upper quantile : 5.770675 µs (97.5%)
                   Overhead used : 1.686448 ns

Found 1 outliers in 6 samples (16.6667 %)
	low-severe	 1 (16.6667 %)
 Variance from outliers : 31.5509 % Variance is moderately inflated by outliers
=> nil