Hi Iโm working with monger the mongoDB Clojure wrapper, Iโm trying to create a user on the database, the function seems simple enough
add-user
(add-user db username password)
Adds a new user for this db
but when I do something like this
(db/add-user db "test" "12345")
It gives this error.
java.lang.String cannot be cast to [C
What does this error mean?
If its any help, this is what the function looks like in the monger source code
(defn add-user
"Adds a new user for this db"
[^DB db ^String username ^chars password]
(.addUser db username password))
Thanks in advanceBoth [C
and ^chars
are used for arrays of characters (which is different from String).
Does (db/add-user db "test" (.toCharArray "12345"))
work?
Oh that works! If you donโt mind me asking, whats the difference between (char "12345")
and (.toCharArray "12345")
char
will try to cast its argument to a single character (type is char
) and (.toCharArray "asf")
will return an array of chars (type is similar to char[]
) for a given string
That makes sense, thanks!!!
why (- 5 -10)
gives 15 ?
this is called prefix notation.
(- 5 -10)
in clojure is equivalent to (5 - (-10))
in regular math
can i define clojure.test
tests in a loop?
(defn generate-tests
[]
(deftest "major test"
(for [case [1 2 3]]
(testing (str "is " case " = 1")
(is (= 1 case))))))
(macro error)I do it like this:
(defn exercise-case
[x]
(is (= 1 x)
(str "is" x "= 1")))
(deftest exercise-1
(exercise-case 1))
(deftest exercise-2
(exercise-case 2))
(deftest exercise-3
(exercise-case 3))
note that the second arg to is
is printed on test failure, just like testing
but it can be calculated on demand in its scopeuse doseq
for is not a loop
putting defs inside other forms is pretty much never good
heh, yeah i knew the for wouldn't work there
why didn't i think of doseq.. thanks @dpsutton
yup, i get triggered every time i read through https://github.com/ptaoussanis/sente
https://clojure.github.io/clojure/clojure.test-api.html#clojure.test/are
is there a function to check if a given symbol is a multimethod?
(instance? clojure.lang.MultiFn x)
ty ty
a given object
Is it best practice under Linux to install leiningen from the distro's package manager, or should I install something under my user?
The package manage will be slightly simpler and familiar process and should ensure the binaries do not conflict with anything else on the execution path.
If you wish to have a specific version, then install in _/.local/bin
which is on most exec paths by default if that directory exists.
If configuring a multi-user system and then install in /user/local/bin
using sudo instead.
i'd recommend not using the distro's version. Those come with upgrades prevented. If you install it yourself you can easily run lein upgrade <version>
and easily change the version if there are bugs, incompatibilities, etc
<https://github.com/technomancy/leiningen/blob/master/bin/lein-pkg#L107>