Fork me on GitHub
#beginners
<
2021-06-21
>
Faris04:06:12

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 advance

phronmophobic04:06:10

Both [C and ^chars are used for arrays of characters (which is different from String). Does (db/add-user db "test" (.toCharArray "12345")) work?

Faris04:06:47

Oh that works! If you don’t mind me asking, whats the difference between (char "12345") and (.toCharArray "12345")

phronmophobic04:06:16

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

Faris04:06:26

That makes sense, thanks!!!

popeye17:06:48

why (- 5 -10) gives 15 ?

sova-soars-the-sora19:06:48

this is called prefix notation.

chaow17:06:34

(- 5 -10) in clojure is equivalent to (5 - (-10)) in regular math

joshkh17:06:08

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)

noisesmith16:06:42

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 scope

hiredman17:06:52

for is not a loop

hiredman17:06:28

putting defs inside other forms is pretty much never good

joshkh17:06:27

yup, i get triggered every time i read through https://github.com/ptaoussanis/sente

joshkh17:06:34

heh, yeah i knew the for wouldn't work there

joshkh17:06:48

why didn't i think of doseq.. thanks @dpsutton

jcd20:06:00

is there a function to check if a given symbol is a multimethod?

Jan K20:06:59

(instance? clojure.lang.MultiFn x)

hiredman20:06:04

a given object

echristopherson23:06:22

Is it best practice under Linux to install leiningen from the distro's package manager, or should I install something under my user?

practicalli-john18:06:23

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.

dpsutton23:06:50

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

👍 12
3