This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-10
Channels
- # aleph (1)
- # announcements (21)
- # babashka (3)
- # beginners (98)
- # calva (2)
- # circleci (3)
- # clara (58)
- # clj-kondo (123)
- # cljs-dev (1)
- # cljsrn (7)
- # clojure (162)
- # clojure-europe (2)
- # clojure-finland (7)
- # clojure-italy (5)
- # clojure-nl (6)
- # clojure-sanfrancisco (1)
- # clojure-spec (1)
- # clojure-survey (17)
- # clojure-uk (70)
- # clojuredesign-podcast (2)
- # clojurescript (46)
- # cloverage (5)
- # cursive (2)
- # data-science (22)
- # datascript (1)
- # datomic (60)
- # emacs (3)
- # figwheel-main (1)
- # fulcro (26)
- # graalvm (5)
- # jackdaw (3)
- # leiningen (8)
- # luminus (1)
- # off-topic (8)
- # other-lisps (2)
- # pedestal (27)
- # re-frame (17)
- # reagent (20)
- # reitit (3)
- # shadow-cljs (37)
- # spacemacs (23)
- # sql (69)
- # tools-deps (2)
- # utah-clojurians (9)
- # xtdb (3)
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])
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(def str1 "This is a string")
(str/blank? str1)
)
This yields the error: Syntax error compiling at (core.clj:9:3). No such namespace: str
but this works:
(ns tutorial.core
(:require [clojure.string :as str])
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(def str1 "This is my second string")
(clojure.string/blank? str1)
)
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
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
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
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
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
#vscode
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])
(:gen-class))
(defn -main
[& args]
(println (str/blank? "str1"))
)
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).
@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?"
Hmm, never seen anyone call create-ns
to be honest, but you can just refer to its content via its name...
...so 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.
Example:
user=> (in-ns 'foo)
#object[clojure.lang.Namespace 0x1bb9aa43 "foo"]
foo=> (clojure.core/refer 'clojure.core)
nil
foo=> (defn bar [n] (* n n ))
#'foo/bar
foo=> (in-ns 'user)
#object[clojure.lang.Namespace 0x2e52fb3e "user"]
user=> (foo/bar 4)
16
user=> (alias 'f 'foo)
nil
user=> (f/bar 5)
25
user=>
(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 oops I need coffee, just tested and this does not actually work in 1.10.1(refer-clojure)
even in a namespace where clojure.core isn't referred
(! 1096)-> clj
Clojure 1.10.1
user=> (in-ns 'foo.bar)
#object[clojure.lang.Namespace 0x17ca8b92 "foo.bar"]
foo.bar=> (clojure.core/refer-clojure)
nil
foo.bar=> (defn quux [n] (* n n))
#'foo.bar/quux
foo.bar=> (in-ns 'user)
#object[clojure.lang.Namespace 0x377008df "user"]
user=> (foo.bar/quux 4)
16
user=> (alias 'f 'foo.bar)
nil
user=> (f/quux 5)
25
user=>
^ @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
@lockdown- Does that help?
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 )))
#'foo/bar
user=> (foo/bar 4)
16
user=> (alias 'f 'foo)
nil
user=> (f/bar 5)
25
user=>
@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 []
(try
(let [cid (otocol/<-client-id om)]
(when-let [{r-cid :client-id :as resp}
(async/<! (otocol/<-resp-ch om))]
(if (= r-cid cid)
(.submit
^java.util.concurrent.ExecutorService pool
^Callable (fn []
(handle-resp-on-start
state db om resp db-pool)))
(.submit
^java.util.concurrent.ExecutorService db-pool
^Callable (fn []
(opdb/->response db resp))))))
(catch Exception e
(throw
(ex-info "resp-handler"
{:cause e
:params {:state state}}))))
(recur)))
Thanks a lotthose Callable type hints probably aren't getting applied
but if you pull them up to let locals and then type-hint the local reference, that will work
(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 []
(try
(let [cid (otocol/<-client-id om)]
(when-let [{r-cid :client-id :as resp}
(async/<! (otocol/<-resp-ch om))]
(let [resp-handler (fn []
(handle-resp-on-start
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
(throw
(ex-info "resp-handler"
{:cause e
:params {:state state}}))))
(recur)))
I still get the same reflection-warning.call to method submit on java.util.concurrent.ExecutorService can't be resolved (argument types: unknown).
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
you have to import java.util.concurrent.Callable - it might not be needed in the other cases
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 ?
function objects in general don't have metadata
so that metadata doesn't have anywhere to go
Thanks @alexmiller
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?

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"

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
assert or throw
or you can literally remove it
with remove-method
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
(if @filtered [records ^{:key "t"} true] [records ^{:key "f"} false])
i can't make refresh the records
element when filtered
is changed
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]
(r/with-let
[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]]
))
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
https://reactnavigation.org/docs/en/state-persistence.html
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]
...)))
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 clojure.java.jdbc/queryreplace 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 clojure.java.jdbc/query 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 clojure.java.jdbc/query 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"
you can just use clojure.string/replace
something like
(-> input (str/replace #"[\[\]]" "") (str/replace " " "_"))
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.
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